Destroying balls
Practice
0 (0 votes)
Hiring
Open
Recruit
Hiring
Open
Recruit
Hiring
Sorting
Implementation
Advanced sorting
Advanced sorting
Algorithms
Greedy algorithm
Easy
Problem
37% Success 116 Attempts 30 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\). Your task is to destroy all the balls by using the following operation any number of times:

Assume that the current number of balls is \(k\). All the balls of color \(k\) are destroyed at the same moment. In different scenarios, you are required to determine whether you can destroy all the balls or not.

Input format

  • First line: \(t\) denoting the number of test cases
  • Each test case: An integer \(N\) denoting the number of balls
  • Next line: \(N\) space-separated integers corresponding to the color of balls

Output format
For each test case, if all the balls can be destroyed, then print \(YES\). 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:30
29 votes
Tags:
Basic ProgrammingData StructuresPrefixArraysBasics of Greedy Algorithms1-D
Points:20
979 votes
Tags:
Ad-HocEasyReadyMathematicsOpenApproved
Points:30
1 votes
Tags:
AlgorithmsApprovedGraphsMediumNumber TheoryOpen