Resolve Chained Redirect Rules With Loop Detection

Last updated: November 29, 2026

Quick Overview

Given an ordered list of redirect rules from a project config (source path, destination path, permanent flag), return the final path a request lands on and the status codes of each hop, or report an error if the rules form a loop or exceed a hop limit.

Vercel
Coding & Algorithms
Software Engineer
Vercel
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an ordered list of redirect rules from a project config (source path, destination path, permanent flag), return the final path a request lands on and the status codes of each hop, or report an error if the rules form a loop or exceed a hop limit.

Vercel projects declare redirects in vercel.json or next.config.js, and the edge has to resolve them on every request without ever trapping a browser in an infinite redirect. A phone screen uses this to check clean hash map use, cycle detection and attention to config semantics like first-match-wins and 307 vs 308.

What the Interviewer Expects
  • Build a lookup from source to destination honoring first-match-wins order
  • Follow the chain while tracking visited paths to detect loops
  • Map permanent to 308 and temporary to 307 and explain why not 301/302
  • Enforce a maximum hop count as a second safety net
  • State O(n + hops) time and O(n) space
Key Topics to Cover
Hash maps
Cycle detection
HTTP 307 vs 308
Config validation
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 validate the config at deploy time so loops never reach production?
  • How does this change if sources can contain wildcards like /blog/:slug*?
  • Should the edge collapse a chain into one redirect, and what is lost if it does?
  • How would you handle query strings that must be preserved across hops?
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: ordered rules (source, destination, permanent) and a request path. Output: the final path plus the list of status codes applied. If two rules share a source, the first one wins, matching how ...

High-Level Design

Preprocess the rules once into a dictionary source -> (destination, code), skipping later duplicates. Then walk from the request path, keeping a seen set. Each step is an O(1) lookup. Permanent ma...


Submit Your Answer
Markdown supported

Related Questions