As a programmer, it is very necessary to maintain balance in the things you work upon. Here is task for you to maintain this balance. Your task is to find whether a given number x is balanced with respect to a given array a which is sorted in a non-decreasing order.Given a sorted array, the ceiling of x is the smallest element in array greater than or equal to x, and the floor is the greatest element smaller than or equal to x.The number 'x' is said to be balanced if the floor is equal to ceil of the number in the array a.
ie. if (x - floor(x,a)) == (ceil(x,a) - x)
Assume one of floor or ceil does not exist assume 'x' to be balanced. If Key exists in the array so it is Balanced.
The first line of input contains an integer T denoting the number of test cases. Each test case contains the number of elements in the array a as n and next line contains space separated n elements in the array. The following line consists of the number 'x' for which balance is to be checked.
Output "Balanced" if the number 'x' is balanced otherwise output "Not Balanced".
1 2 8 10 10 12 19
1 2 5 7 8 11 12 15
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.