Resolve the Final Target of Chained Short Link Redirects
Last updated: November 29, 2026
Quick Overview
A short link service stores redirects from one path to another, and targets can themselves redirect. Given the redirect map and a list of starting paths, return each path's final destination, or 'LOOP' if following redirects never terminates.
Meta
November 29, 20260
0
0 solved
A short link service stores redirects from one path to another, and targets can themselves redirect. Given the redirect map and a list of starting paths, return each path's final destination, or 'LOOP' if following redirects never terminates.
A Meta phone screen warm-up inspired by link shims and short links shared across Facebook and Instagram, where chained redirects must be resolved before a link preview is built. The interviewer checks loop detection and whether you add memoization with path compression so repeated lookups stay fast.
What the Interviewer Expects
- Follow the chain until a path has no redirect
- Detect loops with a visited set per walk
- Memoize resolved results and compress the chain
- Mark every node on a loop path as LOOP
- Keep the solution iterative
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 does this relate to path compression in union find?
- How would you resolve redirects when the map is too big for one machine?
- What if a redirect can be updated while lookups are in flight?
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:
redirects, a dict from path to path, andqueries, a list of paths. - Output: for each query, the first path in the chain with no outgoing redirect, or
'LOOP'. - Many queries share chain...
High-Level Design
Each path has at most one outgoing redirect, which makes this a functional graph: following it either reaches a terminal or enters a cycle.
For a query, walk forward collecting the chain until I reac...