Communications Handler
Updated
Problem statement
Implement a communications handler for a single shared communication channel. At most two callers can communicate at a time, and no other pair can connect until the current communication ends.
The input instructions describes method calls in chronological order:
["connect", user1, user2]callsconnectfor the two named callers.["hangup", user1, user2]callshangupfor the two named callers.["clear_all"]callsclear_all.
Caller names uniquely identify the corresponding Caller objects. Treat a connected pair as unordered, so either caller order refers to the same active communication.
Connect
- If
user1anduser2are the same caller, the call raisesCommunicationExceptionwith the message{user1} cannot connect with {user2}. - If the callers are different but the line is already in use, the call raises
CommunicationExceptionwith the messageConnection in use. Please try later. - Otherwise, store the two callers as the active pair and return
Connection established between {user1} and {user2}.
Hangup
- If
user1anduser2are the same caller, the call raisesCommunicationExceptionwith the message{user1} cannot hangup with {user2}. - If the two callers are the active pair, disconnect them and return
{user1} and {user2} are disconnected. - Otherwise, the call raises
CommunicationExceptionwith the message{user1} and {user2} not found in the communication channel.
Clear All
clear_all clears the channel regardless of its current users.
Return an array containing, in order, the returned string or exception message from every connect and hangup instruction. A clear_all instruction produces no output entry.
Function
handleCommunications(instructions: String[][]) → String[]Examples
Example 1
instructions = [["connect","Alice","Bob"],["connect","Carol","Dave"],["hangup","Bob","Alice"],["connect","Carol","Dave"]]return = ["Connection established between Alice and Bob","Connection in use. Please try later","Bob and Alice are disconnected.","Connection established between Carol and Dave"]AliceandBoboccupy the free channel.CarolandDavecannot connect while that pair remains active.hangupaccepts the active pair in reverse order and frees the channel.CarolandDavecan then connect.
Example 2
instructions = [["connect","Mia","Mia"],["hangup","Mia","Noah"],["connect","Mia","Noah"],["hangup","Mia","Mia"],["hangup","Noah","Mia"]]return = ["Mia cannot connect with Mia","Mia and Noah not found in the communication channel.","Connection established between Mia and Noah","Mia cannot hangup with Mia","Noah and Mia are disconnected."]The rejected same-caller calls do not change the channel. The final reversed-order hangup matches the active pair and disconnects it.
Example 3
instructions = [["connect","Ava","Ben"],["clear_all"],["hangup","Ava","Ben"],["connect","Cara","Dan"]]return = ["Connection established between Ava and Ben","Ava and Ben not found in the communication channel.","Connection established between Cara and Dan"]clear_all removes Ava and Ben without adding an output entry. Their later hangup is therefore not found, and the channel remains available for Cara and Dan.
Constraints
1 <= instructions.length <= 2000.- At most
100distinct caller names appear. - Every instruction is one of
["connect", user1, user2],["hangup", user1, user2], or["clear_all"]. - Every caller name is a non-empty, case-sensitive string that uniquely identifies one caller.
More Akuna Capital Online Assessment questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
Similar questions at other companies
- Reliable LLM Call with Independent Retry BudgetsStripe · OAStripe interview questions
- Parcel Event TrackingAirbnb · OAAirbnb interview questions
- Text Editor OperationsMicrosoft · OAMicrosoft interview questions
- Versioned Recipe SystemThe Trade Desk · OA
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)