Solve path normalization and nested iterator | Bridge
|Home/Coding & Algorithms/Bridge
Solve path normalization and nested iterator
Bridge
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
0
0
Normalize Unix-style absolute paths: Given a string representing an absolute Unix file path, return its canonical form. Rules: '.' refers to the current directory, '..' moves one directory up (ignore if already at root), multiple consecutive slashes are treated as a single slash, and no trailing slash should appear in the result except for the root '/'. Implement normalizePath(path: string) and explain your algorithm, time complexity, and space complexity.
Implement a nested-list iterator: Given a nested collection containing integers and lists (which themselves may contain integers or lists arbitrarily), design an iterator that outputs the integers from left to right. Implement hasNext() and next() with a lazy approach that uses a stack to avoid flattening everything up front; optionally discuss an eager alternative. Analyze time and space complexity and compare the trade-offs between the two designs.