Dsa
Stack
Hard
Nested Directory Structure Validator
You are given a string representing a nested directory structure where each directory is denoted by '/' and the base directory is indicated by a trailing '/'. Implement a function that determines if the directory structure is valid. The structure is valid if all directories open and close correctly without mismatched slashes. Output 'Valid' if the structure is valid, otherwise output 'Invalid'.
Input Format:
- A single string representing the nested directory structure.
Output Format:
- 'Valid' or 'Invalid'.
Example:
Input:
//home/user/docs/
Output:
Valid
Key concepts
stackvalidationdirectory
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