Tag Archives: Chef And Babla solution

Chef And Babla solution codechef

Chef And Babla solution codechef – Chef gives an array  with  elements to Babla. Babla’s task is to find the maximum non-negative integer  such that:

  • No element in the array belongs to the range [−�,�]. In other words, for all (1≤�≤�), either ��<−� or ��>�.

Chef And Babla solution codechef

Help Babla to find the maximum non-negative integer  for which the given condition is satisfied or determine if no such  exists.

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • Each test case consists of multiple lines of input.
    • The first line of each test case contains an integer  — the number of elements in the array.
    • The second line of each test case contains  space-separated integers �1,�2,…,�� representing the array .

Output Format

For each test case, output on a new line, the maximum non-negative integer , satisfying the above condition.
If no such  exists, output −1 instead.

Chef And Babla solution codechef

  • 1≤�≤105
  • 1≤�≤105
  • −109≤��≤109
  • Sum of  over all test cases does not exceed 2⋅105.

Sample 1:

Input

Output

3
5
8 4 2 5 2
6
7 9 -10 8 12 17
4
0 -3 -1 -10
1
6
-1

Chef And Babla solution codechef Explanation:

Test case 1: The maximum value of  such that no element of the array belongs to the range [−�,�] is 1. All elements of the array are strictly greater than 1.

Test case 2: The maximum value of  such that no element of the array belongs to the range [−�,�] is 6. All positive elements of the array are strictly greater than 6 and negative elements are strictly less than −6.

Test case 3: It is not possible to choose an element  that satisfies the given condition.