License Checkout and Return Manager
Updated
Problem statement
Implement a license checkout manager for the listed operations. A pool of capacity licenses is shared by users. Process each string in operations in order; it is either checkout,userId or return,userId.
For this exercise, assume licenses are numbered 1 through capacity and each user may hold at most one license. If the user already holds a license, checkout returns that same license; otherwise it assigns the smallest available license. When none is free, return -1.
For this exercise, assume return releases the requesting user's current license and returns its identifier. If that user has no license, return -1 without changing the pool. Operations are sequential and licenses do not expire.
For this exercise, assume operations are valid, contain exactly one comma without spaces, and user identifiers are nonempty case-sensitive alphanumeric strings. Return one integer for each operation; an empty sequence produces an empty result.
Function
licenseOperations(capacity: int, operations: String[]) → int[]Examples
Example 1
capacity = 2operations = ["checkout,amy","checkout,bob","checkout,cat","return,amy","checkout,cat"]return = [1,2,-1,1,1]Amy receives 1, Bob 2, and the full pool rejects Cat. Returning Amy frees 1 for Cat.
Example 2
capacity = 1operations = ["checkout,u","checkout,u","return,u","return,u"]return = [1,1,1,-1]Repeat checkout reuses the same lease; after one successful return, another return has no lease to release.
Constraints
- For this exercise, assume
0 <= capacity <= 10^4. 0 <= operations.length <= 10^4.- User identifier lengths are from
1through30. - Actions are exactly
checkoutorreturn.
More Headway Phone Screen questions
Similar questions at other companies
- Financial Account LedgerStripe · OA · PHONE SCREENStripe interview questions
- Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- Risk-Priority Detection StoreCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Design Authentication ManagerApple · PHONE SCREENApple interview questions
- LLM Provider Pool FailoverPerplexity AI · PHONE SCREENPerplexity AI interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions