Rate this Problem!

Revision en4, by salehin_076923, 2025-06-12 05:30:37

Here is a simple problem made by me. Solve it & Give it a rating in comment section if you want.

Problem Name: Range Mex

You are given $$$n$$$ non-negative integers- $$$a_1,a_2,\ldots,a_n$$$. You have to find $$$mex_i$$$ for each $$$1\le i\leq n$$$ such that $$$mex_i$$$ is the mex of all numbers in the array except the $$$i-th$$$ number. e.g. if $$$a=$$${$$${2,5,0}$$$},

$$$mex_1 = mex(a_2,a_3)=mex(5,0)=1$$$

$$$mex_2 = mex(a_1,a_3)=mex(2,0)=1$$$

$$$mex_3 = mex(a_1,a_2)=mex(2,5)=0$$$

Input: The first line contains a positive number $$$t (1\le t\le 10^4) - $$$ the number of test cases. The description of the test cases follows:

Each test case consists of 2 lines.

The first line contains a positive integer $$$n (1\le n\le 2\cdot 10^5) - $$$indicating the size of array $$$a$$$.

The second line contains $$$n$$$ non-negative integers $$$a_1,a_2,\ldots,a_n (0\le a_i\le 10^9) - $$$ the elements of the array $$$a$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

Output: For each test case, output $$$n$$$ integers- the $$$i-th$$$ of them indicating $$$mex_i$$$.(i.e. $$$mex_1, mex_2, mex_3,\ldots, mex_n)$$$

Examples:

Input:

5
0 1 2 3 4
5
1 0 2 5 9
2
1 2
3
1 0 2
4
4 7 0 1 

Output:

1 0 2 3 3 
0 0 
1 0 2 
2 2 0 1 

Notes: Here for the first test case,

$$$mex_1 = mex(1,2,3,4) = 0$$$

$$$mex_2 = mex(0,2,3,4) = 1$$$

$$$mex_3 = mex(0,1,3,4) = 2$$$

$$$mex_4 = mex(0,1,2,4) = 3$$$

$$$mex_5 = mex(0,1,2,3) = 4$$$

Tags mex, code, greedy

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en12 English salehin_076923 2025-06-12 09:42:18 0 (published)
en11 English salehin_076923 2025-06-12 09:42:00 2 Tiny change: 'ut:\n\n```0 1 2 3 4 ' -> 'ut:\n\n```\n0 1 2 3 4 ' (saved to drafts)
en10 English salehin_076923 2025-06-12 09:37:46 0 (published)
en9 English salehin_076923 2025-06-12 09:35:19 3
en8 English salehin_076923 2025-06-12 09:34:37 178
en7 English salehin_076923 2025-06-12 09:31:21 783
en6 English salehin_076923 2025-06-12 09:18:45 1779
en5 English salehin_076923 2025-06-12 05:31:19 6 Tiny change: ' \n```\n\nNotes:\nHere for' -> ' \n```\n\n**Notes:**\n\nHere for'
en4 English salehin_076923 2025-06-12 05:30:37 17
en3 English salehin_076923 2025-06-12 05:29:32 40
en2 English salehin_076923 2025-06-12 05:28:23 32
en1 English salehin_076923 2025-06-12 05:27:29 1484 Initial revision (saved to drafts)