Dsa
Recursion
Easy
Nested Directory Depth
Given a string representing a nested directory structure with the format 'dir1/dir2/.../dirN', write a program to calculate the maximum depth of the directory. Each '/' separates the directories. If there are no directories, the depth is 0.
Input Format:
- A single line containing the directory structure string.
Output Format:
- A single integer representing the maximum depth of the directory structure.
Example:
Input:
dir1/dir2/dir3
Output:
3
Key concepts
recursiontreedepth calculation
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