KURUK14 - GENIE SEQUENCE

no tags 

A Genie Sequence is a sequence in which every element indicates the number of elements present before or after it. Given an array of numbers, find whether you can form a Genie sequence or not.

Input

First line contains a single integer T, the number of test cases. It is followed by T cases each of which contains two lines. First line of each test case contains a single integer N. The next line contains N integers separated by a single space.

Output

For each test case output a single line containing "YES" (without quotes) if it is possible to form a genie sequence or "NO" (without quotes) if it is not possible.

Constraints

1 <= T <= 20

2 <= N <= 1000

1 <= ai <= 1000

Example

Input:
1
4
1 3 3 2

Output:
YES

Explanation for the test case:

The Genie sequence is {3, 1, 2, 3}. The first element '3' in the sequence indicates that three numbers are after it, the 2nd element '1' indicates that one number if before it, the 3rd element '2' indicates that two elements are before it and the last element indicates that three elements are before it. So the answer is YES.


hide comments
ankit1cool: 2017-06-07 12:58:38

Try using O(n) ,don't go for O(n*n) i

vengatesh15: 2017-03-15 20:50:24

easy one done in O(n)..

strangerx: 2017-02-04 08:13:54

A O(n) solution exist using hashing .

adi_1996: 2016-07-02 21:32:24

easy
O(n^2) works

KD : 2016-05-28 12:16:35

didn't read question carefully costed me 2 WA :-| AC--finally

akshayvenkat: 2016-05-23 07:45:26

O(n*n) works in c++ :D

manjeet24feb: 2016-03-18 19:11:49

What a s*****t question.. Simply waste of time.. Question' s language is not clear. You should mention clearly whether you are allowed to make a genie sequence from a subset of array or not...!! By the way you are only allowed to make genie sequence by using all the numbers.. got AC... if anybody is stuck ....

Last edit: 2016-03-18 21:20:16
RADHE SHYAM LODHI: 2015-08-29 15:11:16

easy took 10 min. only :D

Jaswanth: 2015-08-16 14:43:46

my 200th classical an easy one

Aditya Kumar: 2015-07-01 09:51:52

It gives me Green light => my 100th AC in classical!!!


Added by:785227
Date:2014-01-31
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C CSHARP C++ 4.3.2 CPP C99 JAVA PERL PYTHON PYTHON3
Resource:Kurukshetra Onsite Programming Contest