#2672
Number of Adjacent Elements With the Same Color
medium · 58.6% accepted · 397 likes · top 55%
Description
You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [indexi, colori]. For the ith query:
- Set colors[indexi] to colori.
- Count the number of adjacent pairs in colors which have the same color (regardless of colori).
Return an array answer of the same length as queries where answer[i] is the answer to the ith query.
Solution