Consecutive elements
Level MEDIUM
You are given an array arr of N non-negative integers, you need to return true if the array elements consist of consecutive numbers otherwise return false.
Level MEDIUM
You are given an array arr of N non-negative integers, you need to return true if the array elements consist of consecutive numbers otherwise return false.
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains an integer 'N', representing the length of the array.
The next line contains 'N' single space-separated integers representing elements of the array.
For each test case, print “True” or “False” in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^5
0 <= arr[i] <= 10^9
Time Limit: 1 sec
1
4
1 2 4 6
False
As 3 and 5 are not in the array. Thus, this makes the array non-consecutive.
1
3
7 9 8
True
Comments
Post a Comment
Please give us your valuable feedback