Posted: 13 Oct, 2020
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.
For Example: If the given array is [4,3,5] then you should return true as all the array elements are in consecutive order.
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.
Output Format :
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
- Get the minimum and maximum element of the array.
- Check if (max-min+1) is equal to N or not, if it is not equal then return false.
- For every element between the minimum and maximum number, check whether it is present in the array or not by using linear search.
- If it is present, then continue, otherwise return false.
- Finally, If we have reached the maximum element that means all elements between the minimum element and the maximum element is present thus return true.
Game of 3
Posted: 11 Jul, 2021
Lexicographic Permutation Rank
Posted: 13 Jul, 2021
Zero Pair Sum
Posted: 22 Jul, 2021
Implement a Queue
Posted: 27 Jul, 2021
Remove K Corner Elements
Posted: 31 Jul, 2021