Chess Tournament Problem Statement

In Ninjaland, a chess tournament is being organized with C chess players attending. They will all stay in a hotel that has N available rooms. Each player will choose one room, and the ith room is located at positions[i] in the hotel. All rooms are in distinct positions.

The focus level for a chess player is defined as the minimum distance between their room and the room of another player. The overall focus of the tournament is the minimum focus level among all players. As the organizer, your task is to assign rooms to players such that the overall focus is maximized.

Example:

Input:
3 players, 5 rooms with positions: 1 2 3 4 6
Output:
2
Explanation:

The optimal allocation is rooms 1, 3, and 6, giving an overall focus level of 2.

Input:

The first line contains an integer T, the number of test cases.
Each test case consists of:
- A line with two integers, N (number of rooms) and C (number of players).
- A line with N space-separated integers representing the positions of available rooms.

Output:

For each test case, output a single integer denoting the maximum overall focus of the tournament.
Each result should be printed on a new line.

Constraints:

  • 1 <= T <= 10
  • 2 <= N <= 10^4
  • 2 <= C <= N
  • 1 <= positions[i] <= 10^9
  • Time Limit: 1 second
Note:
Your task is to implement the function. No need to handle input/output directly.
Be the first one to answer
Add answer anonymously...
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter