Destroying Balls
Practice
4.3 (3 votes)
Implementation
Recruit
Hiring
Easy
Greedy algorithm
Sorting
Problem
36% Success 5077 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are N balls in a row. The \(i^{th}\) ball has color \(A_i\). 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

\(1≤ t ≤ 200\)
\(1≤N≤1000\)
\(1≤A_i≤1000000000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
Tags:
Ad-HocapprovedEasyApproved
Points:20
16 votes
Tags:
Easy
Points:20
2 votes
Tags:
ImplementationSortingEasyEasy