A question I came across in an Interview

Revision en1, by chillua98, 2024-04-26 06:33:05

There was a question I came across in an Online Assessment recently and I was not able to solve it. It goes as follows:-

There are n children in a classroom and the teacher wants to arrange them in a circle, such that the max height between any 2 students is MINIMIZED.

For example:-

N=7 Students: 4 1 3 2 1 2 3

The minimum value of max height diff is 1, if we arrange it as follows:

2 3 4 3 2 1 1

(Just a reminder that the height difference between the first student and the last student is also considered as they are in a circle)

I thought it was involving Binary Search but couldn't come up with a helper function. Could someone please help me out?

Tags general, problem solving

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English chillua98 2024-04-26 06:33:05 732 Initial revision (published)