×

Loading...

1.sort the list. 2. Then

Longest seq must either contain the smallest or not contain the smallest.
a) contains the smallest: use for loop to go thru the rest of the list as the second number, you will get the leap size. Try to use this leap size to test how long the seq can go.
b) doesn't contain the smallest number: use tail recursive to go thru the rest of the list.

Worst time complicity: O(n^3). Average should be close to O(n^2) because the inner loop will end when the first missing number is found.
Report