Dsa
Stack
Hard
Directory Stack
You are tasked with implementing a basic directory navigation system. The user can enter commands: 'cd <directory>' to change the current directory (pushing it onto a stack) or 'cd ..' to go back to the parent directory (popping from the stack). The input will specify a sequence of commands, and your program must output the final directory, representing the current path as a list. Do not push to the stack for invalid commands. Please write a program that processes a list of commands and outputs the final directory path.
Input Format:
A single line of commands separated by commas.
Output Format:
A list of strings representing the current directory path.
Example:
Input:
cd home,cd user,cd ..,cd documents
Output:
['home', 'user', 'documents']
Key concepts
stackdirectoriesnavigation
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