Need help with this Question i found on a mock interview prep test.
Anonymous User
97

Problem statement : One day the teacher decides to entertain her kids by organizing a simple passing the ball game. She asks her students to stand randomly on a line marked with continuous numbers starting from one. She gives a small ball randomly to a student hoping that she can pass it to her adjacent student. But she notices that the students can't pass if the difference between the numbers on which they're standing is greater than 2.

Help the teacher to identify the maximum and minimum number of students that can receive the ball , if she gives it randomly to any one student.

Input format :

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N
The second line contains N space separated integers.
Output format : T lines of space separated integers , where the first one is the minimum and the second one is the maximum .

Sample input :

2

4

1 2 3 4

3

1 2 6

Sample output

4 4

1 2

Explanation : In the first case if the teacher gives the ball to any student , all can receive the ball. So the maximum and the minimum is 4

In the second case , if the teacher gives it to 1 or 2 , two students can receive it, that is , 1 can pass to 2 or 2 can pass to 1. But if she gives it to 6, he cannot pass it to anyone. So the maximum is 2 and the minimum is 1.

Comments (1)