Customer Support Line With Cancellations
Updated
Problem statement
A customer support desk answers customers in the order they got in line. The line starts empty, and a customer has at most one place in it at a time. Run the entries of commands in order. Each one is:
"SUBMIT name": ifnameis not in line, put that customer at the back and return"OK". If the customer is already waiting, return"DUPLICATE"and leave the line as it is."SERVE": take the customer at the front out of the line and return their name, or return"NONE"if the line is empty."CANCEL name": take that customer out of the line, wherever they are, and return"OK"; return"NOT_FOUND"if they are not in line."POSITION name": return the customer's place in line as a decimal string,"1"for the front, or"NONE"if they are not in line.
A customer who has been served or cancelled is no longer in line and may submit again; they then go to the back. Return one string per command, in the order of commands.
Function
runSupportQueue(commands: String[]) → String[]Examples
Example 1
commands = ["SUBMIT ann","SUBMIT bo","SUBMIT cy","POSITION cy","SERVE","POSITION cy","SUBMIT ann","SERVE","SERVE","SERVE","SERVE"]return = ["OK","OK","OK","3","ann","2","OK","bo","cy","ann","NONE"]The line is ann, bo, cy, so cy is in place 3. SERVE removes ann, the earliest, and cy moves up to place 2. When ann submits again she goes to the back of the line, behind cy. The next three SERVE commands return bo, cy and ann, and the last finds nobody.
Example 2
commands = ["SUBMIT dee","SUBMIT eli","SUBMIT dee","POSITION dee","CANCEL dee","CANCEL dee","POSITION eli","SUBMIT dee","POSITION dee","SERVE","SERVE","SERVE","CANCEL fay","POSITION fay"]return = ["OK","OK","DUPLICATE","1","OK","NOT_FOUND","1","OK","2","eli","dee","NONE","NOT_FOUND","NONE"]dee is already waiting, so the second SUBMIT dee is a duplicate and she keeps place 1. After CANCEL dee she is out, so a second cancel answers NOT_FOUND, and eli has moved up to place 1. When dee submits again she joins behind eli, in place 2. The serves return eli, dee and then NONE. fay never joined, so cancelling her gives NOT_FOUND and her place is NONE.
Example 3
commands = ["SUBMIT a1","SUBMIT b2","SUBMIT c3","SUBMIT d4","CANCEL b2","POSITION d4","CANCEL a1","SERVE","POSITION d4","SERVE","SERVE"]return = ["OK","OK","OK","OK","OK","3","OK","c3","1","d4","NONE"]Cancelling b2 from the middle leaves a1, c3, d4, so d4 is in place 3. Cancelling the front customer a1 leaves c3, d4. SERVE then returns c3, and d4 moves up to place 1. The last two serves return d4 and NONE.
Constraints
1 <= commands.length <= 2000- Each command has one of the four forms above, with a single space, and is 5 to 15 characters long.
- Every customer
nameis 1 to 6 lowercase letters or digits.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Sliding Window Rate LimiterLotusFlare · ONSITE INTERVIEW
- Sliding-Window Rate LimiterAmazon · ONSITE INTERVIEW
- Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Blocking Connection Pool Operation TraceGoogle · ONSITE INTERVIEWGoogle interview questions
- Per-Element Hit CounterUber · ONSITE INTERVIEWUber interview questions
- Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Article Vote TrackerRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Matching Engine with Order CancellationIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
- Transaction Authorizer with Velocity RulesGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences