Dsa
Stack
Medium
Resilient Path Navigation
A drone processes direction commands: NORTH, SOUTH, EAST, WEST. A command cancels the immediate previous command if they are opposites (e.g., NORTH cancels SOUTH). However, a 'FIX' command makes all commands currently in the history permanent, meaning they can no longer be cancelled by future opposites. Input is one command per line. Output the final list of uncancelled commands.
Example:
NORTH
FIX
SOUTH
EAST
WEST
Output: NORTH SOUTH
Key concepts
stackstring-manipulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now