Reported January 2023
ZipRecruiterstack

Longest Common Normalized Path Suffix

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

ZipRecruiter reportedly put this one in front of candidates in January 2023, and the catch is right in the statement: paths full of.. segments that have to be collapsed before you compare anything. It looks like a string problem wearing a dynamic-programming hint, but the real work is two small steps. Normalize each path with a stack, then find the longest common suffix of segments. If you've got an OA invite and 48 hours, this is very doable. StealthCoder sits invisibly on your screen during the live assessment as a safety net if you blank on the stack step.

The problem

You are given an array of absolute filesystem paths, paths. Every path begins with /.
A path may contain.. parent-directory segments. Simplify every path by processing its segments from left to right: append a regular segment, and remove the most recent regular segment when.. appears. Every input path is valid.
After simplification, find the longest suffix of complete path segments shared by every path. The returned suffix must not contain.. or any other special segment.
Return the suffix with one leading /. If the paths share no trailing segment, return the empty string. For one input path, return its complete simplified path.

Function
commonNormalizedPathSuffix(paths: String[]) → String

Examples
Example 1
paths = ["/a/folder1/../folder1/a/leaf.txt","/b/folder2/../folder1/a/leaf.txt","/a/folder3/folder1/folder1/../a/leaf.txt"]
return = "/folder1/a/leaf.txt"
The normalized paths end with the same three segments: folder1, a, and leaf.txt.
Example 2
paths = ["/a/folder1/../folder1/a/leaf.txt","/a/../b","/a/folder3/folder1/folder1/../a/leaf.txt"]
return = ""
The second path normalizes to /b, so no trailing segment is common to all three paths.
Example 3
paths = ["/docs/draft/../final.txt"]
return = "/docs/final.txt"
With one input, the complete normalized path is the longest common suffix.

Constraints
1 <= paths.length <= 1000
Every path is valid, absolute, and begins with /.
Each path contains at most 200 segments.
The total length of all path strings is at most 200000.
Regular segment names are non-empty and do not equal...

Reported by candidates. Source: FastPrep

Pattern and pitfall

Step one: split each path on /, then walk the segments left to right. Push regular segments, pop on "..". Inputs are guaranteed valid, so you never pop an empty stack. Step two: compare the normalized lists from the end. Take the first path as the reference, then for each position from the back, check that every other path has the same segment at that offset. Stop at the first mismatch or when any path runs out. Join the matched segments with a leading /. The common pitfall is comparing raw strings or characters instead of whole segments, which breaks on names like "folder1" vs "older1". Another is forgetting the empty-string return when nothing matches. The single-path case falls out naturally. Cost is linear in total input length, well inside the 200000 limit. If you freeze mid-OA, StealthCoder can hand you the stack plus suffix-compare skeleton.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Longest Common Normalized Path Suffix cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Common Normalized Path Suffix FAQ

What's the trick in the Longest Common Normalized Path Suffix problem?+

Normalize first, compare second. Use a stack per path: push regular segments, pop on "..". Then compare the resulting segment lists from the back, one whole segment at a time. Don't compare characters or raw strings, because the unnormalized paths look nothing alike.

Is dynamic programming actually needed here?+

No. The hinted DP isn't required. A stack handles normalization and a simple backward scan finds the common suffix. Total work is linear in the combined path length. If you reach for a DP table, you're overbuilding it.

What edge cases should I test before submitting?+

Test a single path, which should return its full normalized path. Test paths with no shared trailing segment, which returns an empty string. Test paths of different lengths where one is a pure suffix of another. Also test a path that collapses entirely, like /a/.., which normalizes to root.

How should I split and rebuild the path?+

Split on "/" and skip empty strings, since the leading slash creates one. After finding the common segments, join them with "/" and prepend a single "/". If the common list is empty, return "" rather than "/", as the problem asks for the empty string.

How do I prepare for this in 48 hours?+

Write the stack normalizer from memory until it's automatic, then write the backward suffix comparison. Run Example 1 and Example 2 by hand. This is the same shape as Simplify Path plus a common-suffix check, so two focused sessions are enough.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it