Unusual Binary Search ?? Sprinklr OA 2021 Intern
Anonymous User
1176

It was hosted on hackerearth platform.
The question which tricked me was like this -
Given an array of coordinates of houses, choose 3 coordinates (not necessarily from given coordinates) , assume x1, x2, x3. Each x is releasing an energy which is covering the range [x-E, x+E]. Note that each x releases same amount of energy, i.e. E. Your task is to minimize E such that all houses are covered and print it.
Sample TC -
I/p -> 3 4 5 6
O/p -> 0.5
1st alien - 3.5
2nd alien - 4.5
3rd alien - 5.5
Note that you shoud print your answer by rounding off to one decimal place.

UPD -> multiply each coordinate by 2 and then apply binary search and finally divide the answer by 2. Because of symmtery, answer will always be an integer or .5 in decimal place.

Comments (10)