|
| 1 | +<p>You are given an integer <code>limit</code> and a 2D array <code>queries</code> of size <code>n x 2</code>.</p> |
| 2 | + |
| 3 | +<p>There are <code>limit + 1</code> balls with <strong>distinct</strong> labels in the range <code>[0, limit]</code>. Initially, all balls are uncolored. For every query in <code>queries</code> that is of the form <code>[x, y]</code>, you mark ball <code>x</code> with the color <code>y</code>. After each query, you need to find the number of <strong>distinct</strong> colors among the balls.</p> |
| 4 | + |
| 5 | +<p>Return an array <code>result</code> of length <code>n</code>, where <code>result[i]</code> denotes the number of distinct colors <em>after</em> <code>i<sup>th</sup></code> query.</p> |
| 6 | + |
| 7 | +<p><strong>Note</strong> that when answering a query, lack of a color <em>will not</em> be considered as a color.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<div class="example-block"> |
| 13 | +<p><strong>Input:</strong> <span class="example-io">limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]</span></p> |
| 14 | + |
| 15 | +<p><strong>Output:</strong> <span class="example-io">[1,2,2,3]</span></p> |
| 16 | + |
| 17 | +<p><strong>Explanation:</strong></p> |
| 18 | + |
| 19 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop.gif" style="width: 455px; height: 145px;" /></p> |
| 20 | + |
| 21 | +<ul> |
| 22 | + <li>After query 0, ball 1 has color 4.</li> |
| 23 | + <li>After query 1, ball 1 has color 4, and ball 2 has color 5.</li> |
| 24 | + <li>After query 2, ball 1 has color 3, and ball 2 has color 5.</li> |
| 25 | + <li>After query 3, ball 1 has color 3, ball 2 has color 5, and ball 3 has color 4.</li> |
| 26 | +</ul> |
| 27 | +</div> |
| 28 | + |
| 29 | +<p><strong class="example">Example 2:</strong></p> |
| 30 | + |
| 31 | +<div class="example-block"> |
| 32 | +<p><strong>Input:</strong> <span class="example-io">limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]</span></p> |
| 33 | + |
| 34 | +<p><strong>Output:</strong> <span class="example-io">[1,2,2,3,4]</span></p> |
| 35 | + |
| 36 | +<p><strong>Explanation:</strong></p> |
| 37 | + |
| 38 | +<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop2.gif" style="width: 457px; height: 144px;" /></strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li>After query 0, ball 0 has color 1.</li> |
| 42 | + <li>After query 1, ball 0 has color 1, and ball 1 has color 2.</li> |
| 43 | + <li>After query 2, ball 0 has color 1, and balls 1 and 2 have color 2.</li> |
| 44 | + <li>After query 3, ball 0 has color 1, balls 1 and 2 have color 2, and ball 3 has color 4.</li> |
| 45 | + <li>After query 4, ball 0 has color 1, balls 1 and 2 have color 2, ball 3 has color 4, and ball 4 has color 5.</li> |
| 46 | +</ul> |
| 47 | +</div> |
| 48 | + |
| 49 | +<p> </p> |
| 50 | +<p><strong>Constraints:</strong></p> |
| 51 | + |
| 52 | +<ul> |
| 53 | + <li><code>1 <= limit <= 10<sup>9</sup></code></li> |
| 54 | + <li><code>1 <= n == queries.length <= 10<sup>5</sup></code></li> |
| 55 | + <li><code>queries[i].length == 2</code></li> |
| 56 | + <li><code>0 <= queries[i][0] <= limit</code></li> |
| 57 | + <li><code>1 <= queries[i][1] <= 10<sup>9</sup></code></li> |
| 58 | +</ul> |
0 commit comments