Destroying Balls

4.3

3 votes
Implementation, Recruit, Hiring, Easy, Greedy algorithm, Sorting
Problem

There are N balls in a row. The ith ball has color Ai. You have to destroy all of the balls by using the following operation any number of times.

Operation: Let the current number of balls be k. All the balls of color k are destroyed at the same moment. Given the different scenarios, tell whether you will be able to destroy all the balls or not.

Input Format:
First line contains t, the number of test cases.
Each of the test case contains an integer N, the number of balls.
Next line contains N space separated integers corresponding to the color of balls.

Output Format:
For each test case, print “YES”(without quotes) if all balls can be destroyed otherwise “NO”.

Constraints

1t200
1N1000
1Ai1000000000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Initially, there are 6 balls. Now, all balls having color equal to 6 are destroyed together at the same moment. Now, there are 3 balls remaining.

All balls having color equal to 3 are destroyed together at this moment. Now, there is only 1 ball remaining. All balls having color equal to 1 are destroyed together at this moment.

After this operation, all balls have been destroyed. Thus, the answer is yes.

Editor Image

?