#K32992. Minimum Communication Groups
Minimum Communication Groups
Minimum Communication Groups
You are given several test cases. In each test case, there are n soldiers with given ranks. Two soldiers can communicate directly if their ranks differ by exactly 1. In other words, if two consecutive soldiers in the sorted order have ranks ri and ri+1, they belong to the same group if and only if $r_{i+1} - r_{i} = 1$. Otherwise, a new group is required.
Your task is to compute the minimum number of groups required so that every soldier can indirectly communicate with every other soldier in his group via a chain of direct communications.
Input: The first line contains an integer T indicating the number of test cases. For each test case the first number is an integer n (the number of soldiers) followed by n integers representing their ranks.
Output: For each test case, output one integer representing the minimum number of communication groups required. Each answer should be printed on a new line.
inputFormat
The input begins with an integer T (number of test cases). For each test case, the first integer n specifies the number of soldiers, followed by n space-separated integers which denote the ranks of the soldiers.
Example:
2 5 4 1 2 3 5 3 3 10 2
outputFormat
Output the minimum number of groups required for each test case on separate lines.
Example:
1 2## sample
2
5 4 1 2 3 5
3 3 10 2
1
2
</p>