FastPrepProcess Completion Order
Problems/Process Completion Order

Process Completion Order

Morgan Stanley logoMorgan Stanley● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Morgan Stanley onsite interview for interns. The report describes a circular set of active processes and a waiting queue. The author describes fixed-size active positions, completed process IDs, queue refills, and the other durations all dropping by a fixed amount at once. Here we define numbered slots, ticks that happen at once, FIFO batches, the order for ties, and when refills happen. These exact rules and the limits were not written down.

Our version is about 85% the same as the reported question.

Simulate processes in slots fixed active positions arranged in a circle, with a FIFO waiting queue. Process i+1 has the duration stored at durations[i]. Initially put the first processes into slots numbered 0 upward, up to the available slot count; the remaining processes wait in input order.

For this exercise, one logical tick reduces the remaining duration of every active process by quantum simultaneously. After that reduction, every process with remaining duration at most 0 completes. Append their IDs in increasing slot-number order for ties.

After handling that whole completion batch, refill its vacant slots in increasing slot-number order, taking waiting processes from the front of the queue. A replacement starts with its full original duration and first receives work on the next tick. Slots without a replacement stay vacant; active processes keep their slot numbers. The circular scan always starts at slot 0.

Return the process IDs in completion order. An empty duration array returns an empty result. Continue until the active positions and waiting queue are empty. Leave the input array unchanged; this is a finite logical simulation rather than real concurrent execution.

Function

processCompletionOrder(durations: int[], slots: int, quantum: int) → int[]

Examples

Example 1

durations = [5,1,3,2]slots = 2quantum = 1return = [2,3,1,4]

Processes 1 and 2 start in slots 0 and 1. Process 2 completes at tick 1, and process 3 starts in that slot on tick 2 and completes at tick 4. Process 4 then starts there on tick 5 and completes at tick 6. Process 1 completes at tick 5, so the order is [2,3,1,4].

Example 2

durations = [2,2,1,1]slots = 2quantum = 2return = [1,2,3,4]

Processes 1 and 2 both complete after tick 1. Slot order emits [1,2], then processes 3 and 4 refill those slots and complete after tick 2. They cannot run during the refill tick. The final order is [1,2,3,4].

Constraints

  • For this exercise, assume 0 <= durations.length <= 100.
  • Every duration is between 1 and 100, inclusive.
  • For this exercise, assume 1 <= slots <= 10.
  • For this exercise, assume 1 <= quantum <= 100.

More Morgan Stanley Onsite Interview questions

  • Generate Strings of Length at Least ThreeONSITE INTERVIEW · Seen Sep 2026
  • Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Array ElementONSITE INTERVIEW · Seen Jul 2026
  • Run-Length Encode Consecutive Letter RunsONSITE INTERVIEW · Seen Jul 2026
  • Maximum Edge Removals for Two TravelersONSITE INTERVIEW · Seen Oct 2025
  • Remove K DigitsONSITE INTERVIEW · Seen Oct 2025
  • Count Ideal ArraysONSITE INTERVIEW · Seen Aug 2023
  • Distinct Palindrome PartitionsONSITE INTERVIEW · Seen Aug 2023
  • LFU Cache OperationsONSITE INTERVIEW · Seen Aug 2023
  • All-Pairs Shortest PathsOA · ONSITE INTERVIEW · Seen Feb 2022

Similar questions at other companies

  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Bounded Producer–Consumer QueueMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • First Unique ID in a StreamDoorDash · ONSITE INTERVIEWDoorDash 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
  • Concurrent Buffered File LoggerDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Bounded Token-Bucket Request QueuePlaid · ONSITE INTERVIEWPlaid interview questions
  • Streaming Ingredient DishesHarness · ONSITE INTERVIEW

Interview reports that mention this question

  • Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)

Morgan Stanley interview experiences

  • Morgan Stanley Apprenticeship and Tech Interviews: 6 Experiences
  • Morgan Stanley New Grad Technology Analyst: 2 Experiences
  • Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
  • Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
  • Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)
All Morgan Stanley interview questionsSee Morgan Stanley hiring insights
Saved
class Solution {
    public int[] processCompletionOrder(int[] durations, int slots, int quantum) {
        // Write your code here.
    }

}
Checking account…