#K11226. Longest Consecutive Card Sequence
Longest Consecutive Card Sequence
Longest Consecutive Card Sequence
You are given several card sets. Each card set is a collection of integers which may contain duplicates. Your task is to determine the length of the longest sequence of consecutive integers in each card set. A consecutive sequence is defined as a set of numbers in which every number is exactly 1 more than its predecessor. Note that duplicates should be treated as one occurrence.
For example: In the card set [1,2,3,4,6,7,8], the longest consecutive sequence is [1,2,3,4] which has a length of 4, even though there is another consecutive part [6,7,8] with a length of 3.
You need to output the longest consecutive sequence length for each set in the order they are provided.
inputFormat
The first line contains an integer T representing the number of card sets. Each of the following T lines describes a card set. Each card set starts with an integer m denoting the number of cards in the set, followed by m space-separated integers.
Example:
2 7 1 2 3 4 6 7 8 5 10 20 30 40 50
outputFormat
Output a single line containing T integers. Each integer represents the length of the longest consecutive sequence in the corresponding card set, in the same order as the input. The numbers should be separated by a single space.
Example:
4 1## sample
2
7 1 2 3 4 6 7 8
5 10 20 30 40 50
4 1