Reverse a Linked List
Reported by candidates from Mygate's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Mygate OA reported in September 2026 hands you a singly linked list and one rule: reuse the existing nodes. The original head becomes the tail and points to null, and an empty list stays empty. That's the classic reverse linked list, and it's a three-pointer walk (prev, curr, next), which is why the hinted pattern is two-pointers. It's short, but people still blank on the pointer order under a timer. If that happens during the live assessment, StealthCoder sits invisibly on your screen and gives you the working solution while you keep typing.
The problem
Given the head of a singly linked list, reverse its links and return the new head. Reuse the existing nodes. Each node must point to the node that preceded it in the original list; the original head becomes the tail and points to null. The input is acyclic. An empty list remains empty. Lists are displayed as arrays of their node values. Function reverseList(head: ListNode) → ListNode Examples Example 1 head = [2,5,8] return = [8,5,2] The original last node becomes the head. The node order changes from 2 → 5 → 8 to 8 → 5 → 2. Example 2 head = [4,4,-1] return = [-1,4,4] Reversal preserves all three nodes, including both nodes with value 4. Constraints The list has 0 to 1000 nodes. Each node value is an integer in [-10^6, 10^6]. Node values may repeat. The input contains no cycle.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to flip each link as you walk. Keep prev as null and curr as head. On each step, save curr.next into a temp variable, set curr.next to prev, move prev to curr, then move curr to the saved next. When curr is null, prev is the new head. Return prev. That's O(n) time and O(1) space, and it reuses the nodes as the statement requires. The common pitfall is overwriting curr.next before you save it, which orphans the rest of the list. The second is forgetting the empty list. With 0 nodes, the loop never runs and you return null, so it works without a special case. Duplicate values like [4,4,-1] don't matter because you move pointers, not values. If you freeze on the pointer order mid-assessment, StealthCoder is the hedge that gets you the clean iterative version fast.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Reverse a Linked List 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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as reverse linked list. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Mygate's OA.
Mygate 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.
Reverse a Linked List FAQ
How hard is the Mygate reverse linked list question really?+
It's easy on paper. The list has at most 1000 nodes, so there are no performance traps. The difficulty is purely pointer bookkeeping. If you can write the prev, curr, next loop from memory, you're done in a few minutes.
What's the trick to reversing the list?+
Save the next node before you change anything. Then point curr.next at prev, advance prev to curr, and advance curr to the saved node. When curr hits null, prev is your new head. Return it.
Do I need to handle the empty list separately?+
Not if you write the loop as while curr is not null. With an empty list, head is null, the loop never runs, and prev is still null. Returning prev gives you the empty list the problem expects.
Should I use recursion or iteration?+
Iteration. It uses O(1) extra space and has no stack concerns. Recursion works fine for 1000 nodes, but it's easier to get wrong under pressure. Use the iterative loop unless the assessment asks for recursion.
How do I prepare for this in 48 hours?+
Write the iterative reversal from scratch three times on a blank editor, then trace [2,5,8] by hand. Test the empty list and a single node. Once you can do that without looking, you're ready for this pattern.