 Timer is Running

Balance with respect to an array
##### Submissions: 808   Accuracy: 24.19%   Difficulty: Basic   Marks: 1

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.

Input:
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:
Output "Balanced" if the number 'x' is balanced otherwise output "Not Balanced".

Constraints:
1<=T<=100
1<=n<=100000
1<=a[i]<=100000
1<=x<=100000

Example:
Input:

2
7
1 2 8 10 10 12 19
5
8
1 2 5 7 8 11 12 15
9
Output:
Balanced
Not Balanced

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat jain
Author: shashwat jain

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.