
Asked in Deutsche Bank
Longest Consecutive Sequence Problem Statement
You are given an unsorted array/list ‘ARR’ of ‘N’ integers. Your task is to return the length of the longest consecutive sequence.
The consecutive sequence is of the form [‘NUM’, ‘NUM’ + 1, ‘NUM’ + 2, ..., ‘NUM’ + L] where ‘NUM’ is the starting integer of the sequence and ‘L’ + 1 is the length of the sequence.
Note:
If there are any duplicates in the given array, we will count only one of them in the consecutive sequence.
Input:
The first line of input contains a single integer ‘T’, representing the number of test cases. Then the ‘T’ test cases follow. The first line of each test case contains an integer ‘N’, denoting the size of the array. The second line of each test case contains ‘N’ space-separated integers, elements of the array.
Output:
For each test case, print an integer in a single line that represents the length of the longest consecutive sequence.
Example:
Input: ARR = [9,5,4,9,10,10,6] Output: 3 Explanation: The longest consecutive sequence is [4,5,6].
Constraints:
- 1 <= T <= 10
- 1 <= N <= 105
- -109 <= ARR[i] <= 109
Time Limit: 1 sec

AnswerBot
4mo
Find the length of the longest consecutive sequence in an unsorted array of integers.
Sort the array to make it easier to identify consecutive sequences.
Use a set to store unique elements and check for...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Deutsche Bank
Q. What are the basic definitions of OOPS?
Q. Coding challenge in Java 8
Q. Objects in java 8
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Deutsche Bank Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

