Help Ninja to Cross River
1. The first jump will always be of 1 unit. 2. If Ninja's previous jump was ‘X’ units, his current jump must be either ‘X’ - 1, ‘X’, or ‘X’ + 1 units.
If ‘SAFE’ = [1, 2, 4, 7] then it can shown in below image where : Red cell means that the unit is damaged. Green cell means that the unit is safe. We can see Ninja can reach the last unit by making jumps of size 1 , 2 and 3.
The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows. The first line of each test case contains a single integer ‘N’ denoting the size of ‘SAFE’ or we can say the number of safe units. The second line contains ‘N’ space-separated distinct integers denoting the elements of ‘SAFE’.
For each test case return, true if Ninja can cross the river else return false.
You don’t have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <=10 2 <= N <= 10^3 0 <= SAFE[i] <= 10^5 Time limit: 1 sec
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End