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\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
12 votes
Tags:
Data StructuresHeavy Light DecompositionAdvanced AlgorithmsAlgorithmsGraphs
Points:30
1 votes
Tags:
Grammar-VerifiedReadyRecruitApprovedReadyGrammar-VerifiedRecruitApprovedReadyCombinatoricsHardBasics of CombinatoricsBasic ProgrammingCombinatorics basicsMathematicsMath
Points:50
18 votes
Tags:
GraphsHard
Editorial