FastPrepFinite Web Crawler
Problems/Finite Web Crawler

Finite Web Crawler

MongoDB logoMongoDB● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a MongoDB onsite interview for a full-time role. The task is to build a finite crawler around fetch and parse helpers that are given. Here the helper results come as a finite URL graph. We fixed a start page, exact URL matching, and breadth-first discovery order. The original report did not keep these details.

Our version is about 80% the same as the reported question.

You are given a finite collection of pages. urls[i] is the URL of page i, and links[i] is the ordered list of normalized URLs returned by the provided fetch-and-parse helpers for that page.

Starting from startUrl, crawl the reachable pages in breadth-first order:

  1. Discover startUrl first.
  2. When a discovered page is processed, inspect its links from left to right.
  3. If a link exactly matches a URL in urls and that page has not been discovered, discover it and schedule it for processing.
  4. Ignore links that are not present in the finite collection.

Return the URLs in discovery order. Discover each page at most once. The finite collection, rather than a hostname restriction, defines the crawl boundary.

Follow-up: Concurrent crawling

Explain how you would run fetch-and-parse calls concurrently while scheduling each page at most once. Discuss atomic discovery, a bounded worker pool, and how to detect completion when workers may still discover more pages. If the same discovery order must be preserved, explain how you would separate parallel fetching from ordered scheduling.

This follow-up is a design discussion. Your function still gets the finite set of pages above and returns the breadth-first discovery order. It does not make network requests or start worker threads.

Function

crawlPages(urls: String[], links: String[][], startUrl: String) → String[]

Examples

Example 1

urls = ["https://a.test/start","https://a.test/docs","https://b.test/news","https://a.test/end"]links = [["https://a.test/docs","https://b.test/news","https://missing.test/page"],["https://a.test/end"],["https://a.test/end","https://a.test/start"],[]]startUrl = "https://a.test/start"return = ["https://a.test/start","https://a.test/docs","https://b.test/news","https://a.test/end"]

The start page discovers the docs page and the cross-domain news page in that order. The missing page is outside the finite collection. The docs page then discovers the end page; later links to already discovered pages do not add them again.

Example 2

urls = ["https://site.test/root","https://site.test/a","https://site.test/b","https://site.test/isolated"]links = [["https://site.test/a","https://site.test/a"],["https://site.test/b"],["https://site.test/root"],["https://site.test/root"]]startUrl = "https://site.test/root"return = ["https://site.test/root","https://site.test/a","https://site.test/b"]

The duplicate link to a and the cycle back to root are ignored after discovery. The isolated page is present in the collection but is not reachable from the start page.

Example 3

urls = ["https://x.test/alpha","https://x.test/beta","https://x.test/start","https://x.test/zeta"]links = [[],["https://x.test/alpha"],["https://x.test/beta","https://outside.test/no-copy"],["https://x.test/start"]]startUrl = "https://x.test/start"return = ["https://x.test/start","https://x.test/beta","https://x.test/alpha"]

The start page need not be first in urls. The outside link is ignored because it has no supplied page, and zeta is not reachable.

Constraints

  • 1 ≤ urls.length ≤ 5,000.
  • links.length = urls.length.
  • Every value in urls is a unique normalized absolute HTTP or HTTPS URL.
  • startUrl appears exactly once in urls.
  • Every entry in links is a normalized absolute HTTP or HTTPS URL and may be absent from urls.
  • The total number of entries across all links[i] is at most 100,000.
  • Two URLs are equal only when they match exactly, including letter case. Do not follow redirects, remove fragments, or clean up URLs in any other way.

More MongoDB interview questions

  • JSON Path Lookup with Implicit Array WildcardsONSITE INTERVIEW · Seen Nov 2026
  • String Interpolation with a Missing-Value ModePHONE SCREEN · Seen Nov 2026
  • Build Packages as Dependencies Are DiscoveredPHONE SCREEN · Seen Oct 2026
  • Lazy K-Way Union IteratorPHONE SCREEN · Seen Oct 2026
  • Recursive Nested JSON Key SearchPHONE SCREEN · Seen Aug 2026
  • Predicate Expression Tree EvaluatorPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
  • Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
  • Currency Conversion RateAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Hierarchical Permission CheckeBay · ONSITE INTERVIEWeBay interview questions
  • Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
  • Minimum Currency ConversionsEPAM · PHONE SCREENEPAM interview questions
  • Currency Conversion RateBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Currency Conversion RateMercor · ONSITE INTERVIEWMercor interview questions
  • Clone a Connected GraphAbridge · PHONE SCREENAbridge interview questions

MongoDB interview experiences

  • MongoDB Experienced SWE Interviews (Atlas Growth): 1 Experience
All MongoDB interview questionsSee MongoDB hiring insights
Saved
class Solution {
    public String[] crawlPages(String[] urls, String[][] links, String startUrl) {
        // Write your code here.
    }
}
Checking account…