Allocate and Reuse Server Names by Type
Updated
Problem statement
Process server-management requests. Each server type has its own set of numbers, starting at 1.
allocate <type>: reserve the smallest positive number not currently used for that type and return the hostname formed by putting the type and number together.deallocate <hostname>: release that active hostname so its number can be reused by a later allocation of the same type.
Return the hostnames produced by all allocation requests, in request order.
Function
allocateServerNames(requests: String[]) → String[]Examples
Example 1
requests = ["allocate api", "allocate api", "allocate site", "deallocate api1", "allocate api"]return = ["api1", "api2", "site1", "api1"]The api type allocates 1 and 2. The site type starts its own numbering at 1. After api1 is released, the next API allocation reuses it.
Example 2
requests = ["allocate db", "deallocate db1", "deallocate db1", "allocate db", "allocate db"]return = ["db1", "db1", "db2"]The second deallocation is ignored because db1 is already free. The next allocation reuses db1, and the following one receives db2.
Constraints
1 <= requests.length <= 10^5.- Server types contain lowercase English letters.
- Allocated server numbers are positive integers.
- Every request is either
allocate <type>ordeallocate <hostname>. - For this exercise, assume an invalid or already released hostname is ignored.
More Stripe Phone Screen questions
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Dec 2026
- Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
- Merchant Payout Reserve CalculatorPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Bank Accounts with Transfers and a Richest LookupRippling · PHONE SCREENRippling interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Risk-Priority Detection StoreCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- LRU Cache with Expiring EntriesPaytm · PHONE SCREENPaytm interview questions