Train Seats and the Waitlist

Medium ⏱ 12 min 47% acceptance ★★★★☆ 4.4
Write allocate(capacity, requests) processing booking requests (name strings) in order: the first capacity get 'confirmed', the rest get 'WL-1', 'WL-2', … Return a dict name → status. Names are unique.

Examples

Example 1
Input
allocate(2, ['ana', 'raj', 'kim', 'zoe'])
Output
{'ana': 'confirmed', 'raj': 'confirmed', 'kim': 'WL-1', 'zoe': 'WL-2'}
Explanation

Two seats, then a numbered waitlist.

Constraints

  • Waitlist numbering starts at 1.
  • Preserve request order semantics.

Topics

Business Logicallocation

Companies

IRCTC TechRedBusMakeMyTrip

Hints

Hint 1

enumerate gives the position.

Hint 2

Position minus capacity numbers the waitlist.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.