Get Priorities After Execution

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

You're looking at an Amazon process scheduling problem where you need to track which processes survive and what their final priorities are after an algorithm runs. The problem statement is incomplete in what you've got, but the pattern is clear: processes are dequeued, their priorities change based on some rule, and surviving processes get reordered. This is a queue simulation with priority mutation. If you blank on the exact algorithm rules during the OA, StealthCoder reads the full problem text and feeds you the solution in real time.

The problem

Several processes are scheduled for execution on an AWS server. On one server, n processes are schedule where the ith process is assigned a priority of priority[i]. The processes are placed sequentially in a queue and are numbered 1, 2,..,n. The server schedules the processes per the following algorithm: Given the initial priority of the processes, find the final priority of the processes which remain after the algorithm terminates. Note that relative the arrangement of remaining processes in the queue remains the same,only their priorities change. Function Description Complete the function getPrioritiesAfterExecution in the editor. getPrioritiesAfterExecution has the following parameter: int priority[n]: the initial prorities of processes Returns int[]: the final priorities of the remaining processes

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core mechanic is a queue-based simulation. Processes start in a queue, get executed in order, and their priorities are modified according to the algorithm rules (which the problem statement hints at but doesn't fully specify in your excerpt). Typically in these problems, the lowest-priority process in the queue is decremented, or processes are re-queued with adjusted priorities until only some survive. The trick is tracking both which processes remain and their final priority values without losing the original order. A deque or list with index tracking works well here. Most candidates overthink this; it's really just simulation. If the algorithm rules are ambiguous during your live OA, StealthCoder will pull the exact wording and give you pseudocode immediately.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Get Priorities After Execution cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Get Priorities After Execution FAQ

Is this a hard-level problem?+

No. It's medium at worst. The difficulty is in understanding the (admittedly vague) problem statement, not the algorithm itself. Simulation problems are pattern-matching once you see the rule. Amazon's version is testing attention to detail and queue manipulation, not deep algorithmic thinking.

What's the trap everyone falls into?+

Forgetting to maintain the original relative order of surviving processes. You'll be tempted to sort or re-index. Don't. The problem explicitly says relative arrangement stays the same. Simulate with a deque or list, remove elements, and output survivors in order.

Do I need to memorize the exact algorithm rules?+

No. The full problem text will be on your screen during the OA. Read it carefully. The rules are deterministic and stated explicitly. Write them down before coding. If you get stuck, re-read the problem statement word-for-word.

How do I handle priority updates without breaking the queue?+

Use a deque with tuples: (original_index, priority). Simulate the algorithm step-by-step. When a process is processed, update its priority and either remove it or re-enqueue it based on the algorithm rules. At the end, filter and return survivors in original order.

Can I solve this in under 20 minutes?+

Yes, easily, once the algorithm rules are clear. Simulation code is short and straightforward. The bottleneck is reading the problem correctly and tracing through an example by hand first. Spend 5 minutes understanding, 10 coding, 5 testing.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it