Login

Top Apple Coding Interview Questions

Problem title

Difficulty

Avg time to solve

Break Number

Moderate

35 mins

Longest Consecutive Sequence

Moderate

40 mins

Word Break-1

Moderate

36 mins

Implement Trie

Hard

41 mins

Find Number Of Islands

Moderate

34 mins

Excel Column Number

Easy

23 mins

Intersection of Linked List

Easy

25 mins

Search In Rotated Sorted Array

Moderate

30 mins

Rotting Oranges

Moderate

20 mins

Reverse Words In A String

Easy

10 mins

Problem

Submissions

35

Avg. time to solve

40 min

Success Rate

70%

Problem Statement

```
If there are any duplicates in the given array we will count only one of them in the consecutive sequence.
```

```
For the given 'ARR' [9,5,4,9,10,10,6].
Output = 3
The longest consecutive sequence is [4,5,6].
```

```
Can you solve this in O(N) time and O(N) space complexity?
```

```
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 integer 'N' denoting the size of the array.
The second line of each test case contains 'N' single space-separated integers, elements of the array.
```

```
For each test case, print an integer in a single line that represents the length of the longest consecutive sequence.
```

```
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
-10^9 <= ARR[i] <= 10^9
Time Limit: 1 sec
```

```
1
5
33 20 34 30 35
```

```
3
```

```
The longest consecutive sequence is [33, 34, 35].
```

```
1
7
1 9 3 10 4 20 2
```

```
4
```

```
The consecutive sequence is in the form ['NUM', 'NUM' + 1, 'NUM' + 2,...,'NUM' + 'L']. So in the given array, the longest consecutive sequence is [1,2,3,4] where 'NUM' = 1 and 'L' = 3. And the length of the sequence will be 'L' + 1 = 4.
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code