As reported: SentinelOne Senior Software Engineer (Bengaluru), 2026. Round 2 started with a project discussion, then a coding problem similar to a multithreaded web crawler; the focus was concurrency and an efficient design.
This is LeetCode 1242 — Web Crawler Multithreaded. Our write-up: /web-crawler-multithreaded.
You are given a URL startUrl and an HtmlParser interface. Crawl every page that is under the same hostname as startUrl, using multiple threads, and return all the URLs you reached, in any order.
interface HtmlParser {
// Returns every URL linked from the page at `url`.
// Blocking: it performs an HTTP request and returns when the request finishes.
List<String> getUrls(String url);
}
Your crawler must:
- start from
startUrl; - call
HtmlParser.getUrls(url)to get the links of a page; - never crawl the same URL twice (never call
getUrlstwice for one URL); - follow only links whose hostname equals the hostname of
startUrl.
All URLs use http:// and no port, so the hostname is the text between http:// and the next / (or the end). http://news.yahoo.com/news and http://news.yahoo.com/us share a hostname; http://news.google.com does not.
Example 1
urls = ["http://news.yahoo.com", "http://news.yahoo.com/news",
"http://news.yahoo.com/news/topics/", "http://news.google.com",
"http://news.yahoo.com/us"]
edges = [[2,0],[2,1],[3,2],[3,1],[0,4]] (page urls[a] links to urls[b])
startUrl = "http://news.yahoo.com/news/topics/"
Output: ["http://news.yahoo.com", "http://news.yahoo.com/news",
"http://news.yahoo.com/news/topics/", "http://news.yahoo.com/us"]
Example 2
urls = ["http://news.yahoo.com", "http://news.yahoo.com/news",
"http://news.yahoo.com/news/topics/", "http://news.google.com"]
edges = [[0,2],[2,1],[3,2],[3,1],[3,0]]
startUrl = "http://news.google.com"
Output: ["http://news.google.com"]
The only page linked from news.google.com pages is on another hostname, so the crawl stops at the start page.
Constraints: 1 <= urls.length <= 1000, 1 <= urls[i].length <= 300, startUrl is one of the urls. Hostnames are 1–63 characters of lowercase letters, digits and -, separated by dots. URLs contain no duplicates and no query strings.
Code runner format: three JSON values, one per line: urls, edges, startUrl (your code sees only startUrl and the parser). Implement crawl(startUrl, htmlParser). The runner sorts your answer before comparing, and reports a wrong answer if getUrls was called more than once for any URL. Its HtmlParser is safe to call from several threads at once.
Clarifications
- Calls to
getUrlsfor different URLs may run at the same time; the order of the returned list does not matter. - A link that points back to an already-crawled page must be skipped, not fetched again.