Consecutive Elements

Given an array arr of N non-negative integers, determine whether the array consists of consecutive numbers. Return true if they do, and false otherwise.

Input:

The first line of input contains a single integer T, representing the number of test cases or queries. Each test case includes two lines: The first line contains an integer 'N', the length of the array. The second line contains 'N' space-separated integers representing the elements of the array. 

Output:

For each test case, print “True” or “False” in separate lines to indicate whether the elements of the array are consecutive. 

Example:

Input: 
T = 1
N = 3
arr = [4, 3, 5]
Output: 
True

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 10^5
  • 0 ≤ arr[i] < 10^9
Note:

No need to print the expected output, just implement the function logic.

AnswerBot
2mo

Determine if an array of non-negative integers contains consecutive numbers.

  • Check for duplicates: Use a set to track unique elements, as duplicates would prevent the array from being consecutive.

  • Range...read more

Help your peers!
Select
Add answer anonymously...
Quikr Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits