
An equilibrium point is a point where net force is 0 i.e repulsive force of left side magnets is equal to the repulsive force of right side magnets.
If there are N magnets, then there will be N - 1 equilibrium points.
The array “ARR” which denotes the positions of the magnets is in a sorted fashion.
If ARR = {1, 3} , then the output will be 2.
Explanation: For two points, the mid-point will have a net force of 0 because the distance from the mid-point will be equal.
The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first line of each test case contains an integer ‘N’ which denotes the number of magnets.
The second line of each test case contains ‘N’ space-separated integers denoting the positions of the magnets on the x-axis.
For each test case, print all the positions of zero net force with accuracy up to 3 decimal points.
Print the output of each test case in a separate line.
1 <= T <= 100
2 <= N <= 1000
0 <= ARR[i] <= 10000
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the given function.
The basic idea is to use binary search to find the equilibrium position.
As we can see the point of 0 force will lie between the coordinates of the pair magnets for which we are checking. In this way, there will be N - 1 such pair.
The searching of the point will be done with the help of a binary search, constantly changing the upper bound( initially the coordinate of the right magnet in the pair) and the lower bound( initially the position of the left magnet in the pair).
The force between two points is inversely proportional to the distance between the two points i.e Force = 1/(x - y) where ‘x’ and ‘y’ are the coordinates of the two points for which the force is to be calculated.