Reported August 2026
Amazonlinked list

Linked-List Queue with Delete and Deduplication

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

Amazon reported this one in August 2026, and it looks like a queue problem until you read the delete operation. Then it's really a linked-list pointer bookkeeping test dressed up as a queue. You build a singly linked queue by hand, with head and tail, and process enqueue, dequeue, delete, and removeAllDuplicates. The logic is easy. The bugs are in the edges: deleting the head, deleting the tail, emptying the list. If you've got an Amazon OA coming, expect to be graded on those edge cases. StealthCoder is there as a safety net if you blank during the live assessment, but the pattern below should carry you.

The problem

Implement a queue whose state is stored in a hand-built singly linked list. The queue starts empty. Process operations from left to right, using the integer at the same index in values when an operation needs an argument.
The supported operations are:
enqueue: append a new node containing values[i] at the tail in O(1) time.
dequeue: remove the head in O(1) time and append its value to the result.
delete: remove the first node, from the head, whose value equals values[i]. If no node matches, leave the queue unchanged.
removeAllDuplicates: retain the first occurrence of every value and remove all later occurrences, preserving the relative order of the retained nodes.
Return the values produced by dequeue operations in encounter order. The value paired with dequeue or removeAllDuplicates is ignored.
Use explicit node, head, and tail references for the queue state. Do not use a library queue, deque, or linked-list container to represent it. An auxiliary membership set may be used only while processing removeAllDuplicates.

Function
processLinkedQueue(operations: String[], values: int[]) → int[]

Examples
Example 1
operations = ["enqueue","enqueue","enqueue","enqueue","enqueue","removeAllDuplicates","dequeue","delete","dequeue"]
values = [3,1,3,2,1,0,0,1,0]
return = [3,2]
Deduplication changes [3,1,3,2,1] to [3,1,2]. The first dequeue returns 3, deletion removes the first 1, and the final dequeue returns 2.
Example 2
operations = ["enqueue","enqueue","enqueue","delete","enqueue","dequeue","dequeue","dequeue"]
values = [4,5,6,6,7,0,0,0]
return = [4,5,7]
Deleting the tail value 6 must repair the tail pointer, so the later enqueue appends 7 after 5.
Example 3
operations = ["enqueue","enqueue","enqueue","delete","dequeue","dequeue"]
values = [8,9,8,8,0,0]
return = [9,8]
delete 8 removes only the first matching node. The later 8 remains behind 9.

Constraints
1 <= operations.length <= 2000
values.length == operations.length
Every operation is enqueue, dequeue, delete, or removeAllDuplicates.
-10^9 <= values[i] <= 10^9
Every dequeue occurs when the queue is nonempty.
The queue state must use hand-built singly linked nodes with explicit head and tail references.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The problem reduces to a singly linked list with a tail pointer and three careful pointer routines. Enqueue and dequeue are O(1). Delete walks from the head with a prev pointer and removes the first match. The trap is the tail: if you remove the last node, set tail to prev, and if the list becomes empty, set both head and tail to null. Example 2 tests exactly this, since the later enqueue must attach after 5. Dedup is one pass with a hash set. Keep a node if its value is new, otherwise unlink it, and again repair tail when you unlink the last node. Don't use a library queue, since the constraints forbid it. With 2000 operations, O(n) per delete or dedup is fine. A dummy head node removes most special cases. If your mind goes blank on the pointer repair mid-assessment, StealthCoder can supply the working version invisibly.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Linked-List Queue with Delete and Deduplication 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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 for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Linked-List Queue with Delete and Deduplication FAQ

How hard is this Amazon OA question really?+

Easy on algorithms, medium on care. There's no clever trick, just pointer handling. Most failures come from forgetting to update the tail when the last node is deleted or when the list empties. Write it slowly and trace the three examples by hand before submitting.

What's the trick for the delete operation?+

Walk from the head keeping a prev pointer. When you find the first match, link prev.next to cur.next. If cur was the head, move head. If cur was the tail, set tail to prev. Stop after the first match, since only one node gets removed.

How do I handle removeAllDuplicates correctly?+

Use a hash set and one pass. For each node, if its value is in the set, unlink it using prev. Otherwise add it and advance prev. After the pass, set tail to the last retained node. The first occurrence always stays, which preserves order.

Can I use a dummy head node?+

Yes, it's a common way to simplify things, as long as you still keep explicit head and tail references in the real queue state. A sentinel removes the head-deletion special case. Just make sure tail points at the sentinel when the queue is empty.

How do I prepare for this in 48 hours?+

Practice writing singly linked list deletion with prev and tail pointers until it's automatic. Then code this problem and test empty-after-delete, delete-tail-then-enqueue, and dedup with all equal values. That covers nearly every failure mode here.

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