Maximize Distance to Closest Person — Return the Seat
Updated
Problem statement
You are given an array seats, where seats[i] = 1 means seat i is occupied and seats[i] = 0 means it is empty. At least one seat is empty and at least one seat is occupied.
Choose an empty seat that maximizes its distance to the closest occupied seat, and return the index of that seat. If several seats have the same maximum distance, return the smallest index.
Function
bestSeat(seats: int[]) → intExamples
Example 1
seats = [1, 0, 0, 0, 1, 0, 1]return = 2Seat 2 is two positions from the closest occupied seat, which is optimal.
Example 2
seats = [1, 0, 0, 0]return = 3The final seat is three positions from the only occupied seat.
Example 3
seats = [0, 1]return = 0Seat 0 is the only empty seat.
Example 4
seats = [1, 0, 0, 1, 0, 0, 1]return = 1Seats 1, 2, 4, and 5 all have closest-person distance 1; the smallest index is 1.
Constraints
2 <= seats.length <= 20000seats[i]is0or1.- At least one seat is empty.
- At least one seat is occupied.
- On a tie, return the smallest seat index.
More Roblox Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Sliding Window: Target Containment and Most-Repeated WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Merge Sorted ArrayDP World · ONSITE INTERVIEW
- Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEW
- Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEW
- Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEW
- Sparse Vector Dot Product from TuplesMeta · ONSITE INTERVIEW
- Make a Sorted Array Unique In PlaceAlpaca · ONSITE INTERVIEW
- Two SumMicrosoft · ONSITE INTERVIEW
- Move ZeroesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Rotate an Array to the RightScale AI · ONSITE INTERVIEW
Roblox interview experiences
- Roblox OA: What It Tests (2026)
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)