Check Whether One Page Can Reach Another Through Links

Last updated: November 29, 2026

Quick Overview

Facebook Pages link to other Pages through directed links. Given n Pages, the list of links, and two Pages src and dst, return True if dst is reachable from src by following links.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Facebook Pages link to other Pages through directed links. Given n Pages, the list of links, and two Pages src and dst, return True if dst is reachable from src by following links.

A basic reachability check in the style of Meta online assessments, where the first task is usually a short graph traversal. The interviewer is checking a clean adjacency list, a visited set, and an early exit once the target is found.

What the Interviewer Expects
  • Builds a directed adjacency list
  • Uses BFS or iterative DFS with a visited set
  • Exits early when dst is found
  • Handles src equal to dst
  • Mentions union-find only for undirected graphs
Key Topics to Cover
Graphs
BFS
Reachability
Directed graphs
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 answer many reachability queries on the same graph?
  • What if links are undirected?
  • How would you return the shortest chain of links?
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: n, directed links as [u, v], src, dst. Output: True if a directed path exists. n and links up to 2 * 10^5, so the traversal must be linear and iterative....

High-Level Design

Build adj[u] for each outgoing link. BFS from src with a visited array. Return True the moment dst is popped or discovered. If the queue empties first, return False. Direction matters: a link from u...


Submit Your Answer
Markdown supported