mediumArray 0 views

Number of Adjacent Elements With the Same Color

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 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:

Return an array answer of the same length as queries where answer[i] is the answer to the ith query.

Example 1

Input: n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]

Output: [0,1,1,0,2]

Example 2

Input: n = 1, queries = [[0,100000]]

Output: [0]

Explanation: After the 1 st query colors = [100000]. The count of adjacent pairs with the same color is 0.

Constraints

  • 1 <= n <= 10^5
  • 1 <= queries.length <= 10^5
  • queries[i].length == 2
  • 0 <= indexi <= n - 1
  • 1 <= colori <= 10^5

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.