AMAZON & MICROSOFT Question – Solved

7 Live
Optimal Points Selection Given a set of n distinct points on the x-axis, choose k of them such that the minimum distance between any two chosen points is as large as possible. Find this maximum possible minimum distance. Example Consider n = 5, k = 3, and x = [1, 4, 2, 9, 8]. In the optimal solution, one of the possible selections of points is [1, 4, 8]. Here, The distance between 1 and 4 = abs(1 - 4) = 3 The distance between 1 and 8 = abs(1 - 8) = 7 The distance between 4 and 8 = abs(4 - 8) = 4 The minimum amongst them is 3, which is the maximum possible. Function Description Complete the function maximizeMinimumDistance in the editor below. maximizeMinimumDistance has the following parameters: int x[n]: the x-coordinates of points int k: the number of points to choose Returns int: the maximum possible minimum distance between any 2 of the chosen points.

Asked in: AMAZON MICROSOFT

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |