FastPrepFIFO Mutex Operation Trace
Problems/FIFO Mutex Operation Trace

FIFO Mutex Operation Trace

Apple logoApple● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple full-time onsite interview. The report asks you to build a lock without calling an existing lock. Our version keeps the exclusive owner, the waiting, the release, and the handoff, shown as an ordered trace of atomic calls. We chose the first-in-first-out fairness, who may act, no re-locking by the owner, the input limits, and how the final answer is written. We did not keep real thread scheduling, memory-order tools, or extra lock calls.

Implement a non-reentrant mutex without using a prebuilt lock. You are given a list of ACQUIRE and RELEASE calls, each paired with an integer actor ID. Each call happens in one indivisible step. Track who owns the lock, who is waiting and who gets it next.

The lock initially has no owner. An acquire on a free lock completes immediately and makes its actor the sole owner. Other acquire calls wait in the order they were made. When the owner releases, its call completes, then the oldest waiting acquire becomes the owner and completes immediately. If nobody waits, the lock becomes free.

Inputs are valid: an actor acquires only when it neither owns nor waits for the lock, and releases only while it is the current owner. After releasing, it may acquire again. After processing the whole trace, return the final result for each call: ACQUIRED for an acquisition eventually granted, WAIT for an acquisition still waiting, and RELEASED for a release. The exercise does not allow the owner to acquire the lock again before releasing it. It also has no try-lock, cancellation, or timeout operation.

Function

runFifoMutex(operations: String[], actors: int[]) → String[]

Examples

Example 1

operations = ["ACQUIRE","ACQUIRE","RELEASE"]actors = [1,2,1]return = ["ACQUIRED","ACQUIRED","RELEASED"]

Actor 1 takes the free lock and actor 2 has to wait. When actor 1 releases, actor 2 becomes the owner, so its final result is ACQUIRED.

Example 2

operations = ["ACQUIRE","ACQUIRE"]actors = [1,2]return = ["ACQUIRED","WAIT"]

Actor 1 takes the lock and actor 2 waits. Nobody releases, so actor 2 is still waiting at the end.

Example 3

operations = ["ACQUIRE","ACQUIRE","ACQUIRE","RELEASE","RELEASE"]actors = [1,2,3,1,2]return = ["ACQUIRED","ACQUIRED","ACQUIRED","RELEASED","RELEASED"]

Actors 2 and 3 wait in that order. When actor 1 releases, actor 2 gets the lock. When actor 2 releases, actor 3 gets it. All three acquires end as ACQUIRED.

Constraints

  • 0 <= operations.length = actors.length <= 2000.
  • Each operation is ACQUIRE or RELEASE.
  • Actor IDs are integers in [0,10^9].
  • Every trace satisfies the ownership and pending-acquire validity rules.

More Apple Onsite Interview questions

  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026
  • Classify Natural-Month Distance Between DatesONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Priority Message BufferAmazon · ONSITE INTERVIEW
  • Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Sliding Window Rate LimiterLotusFlare · ONSITE INTERVIEW
  • Rolling CSAT TrackerDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Rate Limiter with Global and Per-User LimitsOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Per-Element Hit CounterUber · ONSITE INTERVIEWUber interview questions
  • Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String[] runFifoMutex(String[] operations, int[] actors) {
        // Write your code here.
    }

}
Checking account…