#K56697. Longest Connected Sequence
Longest Connected Sequence
Longest Connected Sequence
You are given a list of non-negative integers representing the gold amounts in a row of houses. Your task is to compute the length of the longest sequence of consecutive gold amounts. In other words, after removing any duplicate values, you should find the longest subsequence where every two consecutive numbers differ by exactly 1.
For example, if the list is [0, 1, 2, 4, 5, 6, 7], the longest consecutive sequence is [4, 5, 6, 7] with a length of 4.
If the list is empty, the output should be 0.
Note: The input will be provided via standard input and the output must be written to standard output.
inputFormat
The input consists of two lines:
- The first line contains an integer n representing the number of houses.
- If n > 0, the second line contains n space-separated non-negative integers representing the gold amounts in each house. If n = 0, the second line may be omitted.
outputFormat
Output a single integer representing the length of the longest sequence of consecutive numbers.
## sample7
0 1 2 4 5 6 7
4