Tap here to switch tabs
Problem
Submissions

Problem: Find the Number of Distinct Colors Among the Balls

med
30 min
Try to solve the Find the Number of Distinct Colors Among the Balls problem.

Statement

You are given an integer limit and a 2extD2 ext{D} array queries of size n where queries[i] =[x,y]= [x, y].

There are limit +1+ 1 balls labeled from 00 to limit. Initially, all balls are uncolored. For each query, ball xx is assigned the color yy. If ball xx is already colored, its color is replaced with the new color yy.

Return an array of length n where the value at index ii is the number of distinct colors present among all balls after processing the query at index ii.

Constraints:

  • 1≤1 \leq limit ≤109\leq 10^9

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

  • queries[i].length ==2== 2

  • 0≤0 \leq queries[i][0] ≤\leq limit

  • 1≤1 \leq queries[i][1] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Number of Distinct Colors Among the Balls

med
30 min
Try to solve the Find the Number of Distinct Colors Among the Balls problem.

Statement

You are given an integer limit and a 2extD2 ext{D} array queries of size n where queries[i] =[x,y]= [x, y].

There are limit +1+ 1 balls labeled from 00 to limit. Initially, all balls are uncolored. For each query, ball xx is assigned the color yy. If ball xx is already colored, its color is replaced with the new color yy.

Return an array of length n where the value at index ii is the number of distinct colors present among all balls after processing the query at index ii.

Constraints:

  • 1≤1 \leq limit ≤109\leq 10^9

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

  • queries[i].length ==2== 2

  • 0≤0 \leq queries[i][0] ≤\leq limit

  • 1≤1 \leq queries[i][1] ≤109\leq 10^9