Given an array which is unsorted, check whether the elements are consecutive or not.
E.g. : 1 2 3 4 returns True, 1 3 4 5 returns False
CodingNinjas
author
2y
- Used O(nLog(n)) sorting with merge sort
- Traverse through the arrey, if a[i]+1 != a[i+1] return False
- Else return true
CodingNinjas
author
2y
Brute Force
- 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, ch...read more
CodingNinjas
author
2y
Sorting
- Sort the array in increasing order.
- Get the minimum element (arr[0]) and the maximum element (arr[N-1]) of the array.
- Check if (max-min+1) is equal to N or not, if it is not equal then return fal...read more
CodingNinjas
author
2y
Using Visited Array
- 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.
- Create a visited array that will store true at index...read more
CodingNinjas
author
2y
In Place Algorithm
- 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 each element, check arr[i]-min is negative or not...read more
CodingNinjas
author
2y
Sum of N Natural Numbers
- 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.
- Create a variable arraySum of long type to stor...read more
Chanubala Devi
2y
#include
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i { cin>>arr[i]; } sort(arr,arr+n); for(int i=0;i+1 { if(arr[i]+1!=arr[i+1...read more
Add answer anonymously...
Top NatWest Group Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
NatWest Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app