FastPrepCrawl Reachable Pages on the Starting Host
Problems/Crawl Reachable Pages on the Starting Host

Crawl Reachable Pages on the Starting Host

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Google MLE virtual onsite report says the candidate built a web crawler using DFS and BFS, then discussed Python instance behavior, stack limits, and hash-related bugs. The author called a well-known web-crawler problem an approximate match, without giving its exact prompt. Its official text was not available in the public page we checked. Our version uses a finite page graph and a same-host rule, and does not invent the bug scenarios that were not shared. Our version is about 76% the same as the reported question.

Implement a web crawler over a supplied finite page graph. Start at startUrl and follow outgoing links, visiting each URL at most once. Crawl only pages whose hostname exactly matches the hostname of startUrl.

pageUrls[i] identifies a page and outgoing[i] lists the URLs linked from that page. Every linked URL appears in pageUrls. URLs use lowercase http:// or https:// followed by a hostname and optional path. The hostname is the text between :// and the next /, or the end of the URL. Compare hostnames exactly; scheme and path do not affect the host match.

Return all reachable same-host URLs, including startUrl, once each in lexicographic order. Links to another host are never followed. The supplied graph stands in for an HTML parser; this exercise makes no network requests.

Function

crawlSameHost(startUrl: String, pageUrls: String[], outgoing: String[][]) → String[]

Examples

Example 1

startUrl = "https://alpha.test/home"pageUrls = ["https://alpha.test/home","https://alpha.test/a","https://alpha.test/b","https://other.test/away"]outgoing = [["https://alpha.test/a","https://other.test/away"],["https://alpha.test/b","https://alpha.test/home"],["https://alpha.test/a"],["https://alpha.test/b"]]return = ["https://alpha.test/a","https://alpha.test/b","https://alpha.test/home"]

Only the three reachable pages on alpha.test are returned. The link to another host is ignored.

Example 2

startUrl = "http://site.test/root"pageUrls = ["http://site.test/root","http://site.test/a","http://site.test/hidden"]outgoing = [["http://site.test/a","http://site.test/a"],["http://site.test/root"],[]]return = ["http://site.test/a","http://site.test/root"]

The duplicate link and cycle are visited once; the disconnected page is not reached.

Example 3

startUrl = "https://a.test/"pageUrls = ["https://a.test/","http://a.test/path","https://b.test/"]outgoing = [["http://a.test/path","https://b.test/"],[],[]]return = ["http://a.test/path","https://a.test/"]

Matching hostnames are allowed even when the URL schemes differ. The other host is excluded.

Constraints

  • 1 <= pageUrls.length <= 1000 and outgoing.length == pageUrls.length.
  • startUrl appears exactly once in pageUrls; all page URLs are distinct.
  • Every link in outgoing appears in pageUrls; there are at most 5000 links in total, including duplicates.
  • Each URL is 1 through 100 characters and follows the stated lowercase scheme/hostname format. Hostnames are nonempty.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Currency Conversion RateAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Hierarchical Permission CheckeBay · ONSITE INTERVIEWeBay interview questions
  • Finite Web CrawlerMongoDB · PHONE SCREEN · ONSITE INTERVIEWMongoDB interview questions
  • Currency Conversion RateBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Currency Conversion RateMercor · ONSITE INTERVIEWMercor interview questions
  • Reachable Nodes in a Directed GraphSoFi · ONSITE INTERVIEWSoFi interview questions
  • Fewest Buses with the Full RouteMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Minimum Bus Routes to a DestinationPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Jump Game IVZomato / Eternal · ONSITE INTERVIEWZomato / Eternal interview questions
  • Largest Island After One FlipOracle · ONSITE INTERVIEWOracle interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] crawlSameHost(String startUrl, String[] pageUrls, String[][] outgoing) {
        // Write your code here.
    }
}
Checking account…