Dsa
Sorting
Easy
Filesystem Depth Sorter
When displaying a file tree, it is often helpful to sort paths by their nesting depth.
1. Sort paths by the number of directories deep they are (number of '/' characters).
2. For paths at the same depth, sort them lexicographically.
Input Format:
- An integer N.
- N lines, each containing a file path string (e.g., 'usr/bin/python').
Output Format:
- The sorted paths, one per line.
Example:
Input:
4
a/b/c
x/y
root
a/b/z
Output:
root
x/y
a/b/c
a/b/z
Key concepts
string manipulationstructural sorting
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