Dsa
Strings
Medium
The Ghost Directory
Simulate a filesystem path simplified with a ghost operator '^'. A path is a sequence of directory names separated by '/'. The '.' operator does nothing. The '..' operator removes the previous directory. The '^' operator is a 'ghost' delete: it removes the PREVIOUS TWO directories from the path. If there aren't enough directories to remove for '..' or '^', simply clear the path as much as possible.
Example:
Input: 'usr/lib/config/^/bin'
1. usr, lib, config
2. '^' encounter: remove 'config' and 'lib'
3. Result: 'usr/bin'
Output: 'usr/bin'
Key concepts
stackpath manipulationparsing
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