Ninja Theater Seating Arrangement Problem

As the technical lead of the renowned ninja theater, your task is to implement a system that ensures social distancing by maximizing the distance between seated individuals. This involves determining the best seating arrangement for incoming theater-goers.

Input:

The input begins with an integer 'T' representing the number of test cases.
For each test case:
- The first line contains a single integer ‘N’, indicating the number of seats arranged in a row in the theater.
- The following line contains a single integer, ‘M’, which represents the number of queries.
- Each of the next ‘M’ lines consists of two space-separated integers, ‘type’ and ‘seatNum’.
- For queries of the first type, ‘seatNum’ will be -1.
- For queries of the second type, it corresponds to the seat number of the departing person.

Output:

For each test case, output the results of queries of the first type. Return all the seat numbers a person should choose to maintain maximum distance from the nearest individual, separated by spaces. Each test case's result is on a new line.

Example:

Input:
1
5
3
1 -1
1 -1
2 0

Output:
0 2

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 109
  • 1 ≤ M ≤ 100
  • 1 ≤ type ≤ 2
  • 0 ≤ seatNum ≤ N-1

Note:

No need to print; simply implement the function as specified. Ensure the seating maximizes the distance from the nearest seated person.
AnswerBot
1mo

Implement a system to maximize social distancing in a theater seating arrangement by determining the best seating arrangement for incoming theater-goers.

  • Create a function that takes the number of seat...read more

Help your peers!
Add answer anonymously...
Sanchhaya Education Software Developer Intern 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