FastPrepPage Referrer Reachability
Problems/Page Referrer Reachability

Page Referrer Reachability

Amazon logoAmazon● MediumNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: A follow-up confirmed the original dictionary-shaped records, callable interface, disconnected components, cycles, null-referrer behavior, and same-page result. Numeric bounds were not provided. The judged core task matches the report at about 98%.

Special thanks: ( ˶˘ ³˘)♡ Special thank you to a super lovely and amazing fren who shared this Amazon interview question! ❤️ 🍒

You are given a list of web traffic records. For this cross-language exercise, each record is represented as a two-element string array [url, referrer]:

  • url is the page that a visitor reached.
  • referrer is the page the visitor came from. An empty string represents a direct arrival with no referrer.

Every record whose referrer is non-empty creates a directed movement from referrer to url. The reverse movement is not implied.

The records may describe disconnected components, repeated movements, and directed cycles.

You are also given query = [start, target]. Return true if target is reachable from start by following zero or more recorded movements. Therefore, return true when start and target are the same page. Otherwise, return false.

Direct-arrival records do not create additional movements.

What the interview report shared

The interview used the Python callable can_reach(records: list[dict], query: list[str]) -> bool. Each record was a dictionary with id, url, and referrer fields. The interviewer said that id was irrelevant to reachability and could be ignored. A null referrer represented a direct arrival and created no movement.

This exercise omits the unused id field and serializes a null referrer as an empty string, leaving the same directed-reachability task in a portable form.

Function

canReachPage(records: String[][], query: String[]) → boolean

Examples

Example 1

records = [["/catalog","/home"],["/item/7","/catalog"],["/cart","/item/7"]]query = ["/home","/cart"]return = true

The records create the directed path /home to /catalog to /item/7 to /cart.

Example 2

records = [["/pricing","/home"],["/signup","/pricing"]]query = ["/pricing","/home"]return = false

The record creates a movement from /home to /pricing, but not the reverse movement requested by the query.

Example 3

records = [["/landing",""],["/account","/landing"]]query = ["/account","/account"]return = true

A page is reachable from itself without following an edge.

Constraints

  • 1 <= records.length <= 2 * 10^5.
  • Every row in records contains exactly two strings in the order [url, referrer].
  • Every url, start, and target is non-empty and has length at most 100.
  • Every referrer is either an empty string or a page URL of length at most 100.
  • query.length == 2.
  • Page URLs are compared exactly and are case-sensitive.
  • The records may contain repeated movements and directed cycles.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public boolean canReachPage(String[][] records, String[] query) {
        // Write your code here
    }
}
Checking account…