Imagine you have a collection of numbered balls and a magical palette of colors! 🎨
You start with limit + 1 balls, each labeled with a unique number from 0 to limit. Initially, all balls are colorless - waiting to be painted!
You receive a series of painting instructions in the form of queries [x, y], where:
xis the ball number to paintyis the color to use
After each painting instruction, you need to count how many distinct colors are currently visible among all the balls. Remember: unpainted balls don't count as having any color!
Goal: Return an array where each element represents the number of distinct colors after processing each query.
Example: If you have balls [0,1,2] and queries [[1,3], [0,3], [2,5]], after the first query you have 1 distinct color (3), after the second you still have 1 distinct color (3), and after the third you have 2 distinct colors (3 and 5).
Input & Output
Constraints
- 1 ≤ limit ≤ 105
- 1 ≤ queries.length ≤ 105
- queries[i].length == 2
- 0 ≤ queries[i][0] ≤ limit
- 1 ≤ queries[i][1] ≤ 109
- All ball indices are valid and colors are positive integers