Longest Common Path Prefix Shared by a Batch of Deep Links
Last updated: November 29, 2026
Quick Overview
Given a list of app deep links such as fb://groups/123/posts/9, return the longest prefix made of whole path segments that every link shares, joined back with '/'. Return an empty string if they share no segment.
Meta
November 29, 20260
0
0 solved
Given a list of app deep links such as fb://groups/123/posts/9, return the longest prefix made of whole path segments that every link shares, joined back with '/'. Return an empty string if they share no segment.
Deep links route users into Facebook and Instagram surfaces, and grouping them by shared path is a common debugging task. This is a warm-up that checks careful string splitting and the difference between a character-level and a segment-level prefix.
What the Interviewer Expects
- Split on '/' and compare segments, not characters
- Stop at the first mismatching segment
- Handle a single link and an empty list
- Avoid returning a partial segment like 'fb://groups/12'
- State complexity clearly
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you ignore query strings like ?ref=share?
- How would you find the most common prefix shared by at least half the links?
- How would a trie of segments help if links stream in?
- How should trailing slashes be treated?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of link strings. Output: the shared prefix as a string.
- Prefix must align on segment boundaries:
fb://groups/12andfb://groups/123sharefb://groups, notfb://groups/12. - Emp...
High-Level Design
Split every link with split('/'). Note that fb://groups/1 splits into ['fb:', '', 'groups', '1'], and joining those segments with / restores fb://groups/1 exactly, so the scheme survives the...