Tap here to switch tabs
Problem
Submissions

Problem: Number of Adjacent Elements With the Same Color

Try to solve the Number of Adjacent Elements With the Same Color problem.

Statement

You are given an integer n representing an array of length n where all elements are initially set to $0$, denoting that they are uncolored.

You are also given a 22D integer array queries, where queries[i] = [index_i, color_i].

For each query:

  • Assign color_i to the element at index index_i.

  • Count the total number of adjacent pairs with identical non zero colors.

Return an array answer of the same length as queries, where answer[i] is the count of adjacent equal non zero colored elements after processing the query at index i.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • 0≤0 \leq index_i ≤\leq n −1- 1

  • 1≤1 \leq color_i ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Adjacent Elements With the Same Color

Try to solve the Number of Adjacent Elements With the Same Color problem.

Statement

You are given an integer n representing an array of length n where all elements are initially set to $0$, denoting that they are uncolored.

You are also given a 22D integer array queries, where queries[i] = [index_i, color_i].

For each query:

  • Assign color_i to the element at index index_i.

  • Count the total number of adjacent pairs with identical non zero colors.

Return an array answer of the same length as queries, where answer[i] is the count of adjacent equal non zero colored elements after processing the query at index i.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i].length =2= 2

  • 0≤0 \leq index_i ≤\leq n −1- 1

  • 1≤1 \leq color_i ≤105\leq 10^5