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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
string parsing
longest common prefix
path segments
arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: list of link strings. Output: the shared prefix as a string.
  • Prefix must align on segment boundaries: fb://groups/12 and fb://groups/123 share fb://groups, not fb://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...


Submit Your Answer
Markdown supported