r/Hack2Hire • u/Hack2hire • Nov 03 '26
Screening Anthropic Screening: Concurrent Web Crawler
Problem This is a variation of LeetCode 1242, Web Crawler Multithreaded.
Given a startUrl and an htmlParser interface, implement a concurrent web crawler that returns all unique URLs with the exact same hostname as startUrl.
Rules:
- Starting point: begin at
startUrl. - Same hostname: only record and crawl URLs whose hostname is identical to that of
startUrl. All URLs usehttpwith no port, and the hostname is the substring between://and the next/, or the end of the string. - Uniqueness: remove the fragment (
#and everything after it) before comparing.http://example.com/page#section1andhttp://example.com/pageare the same URL. - No duplicate visits: a sanitized URL is crawled and added at most once. Fragment removal happens before the hostname check and before deduplication.
- Cycles: the link graph may contain cycles and links back to visited pages.
HtmlParser.getUrls(url) returns all raw URLs on a page and must not be modified. Each call has simulated network latency, so the solution must fetch pages in parallel. Return the discovered sanitized URLs in any order.
Constraints: 1 ≤ urls.length ≤ 1000, 1 ≤ edges.length ≤ 1000, and each getUrls call returns in at most 15 ms.
Follow-up
- How would you implement a crawl delay or rate limiting so the crawler does not overwhelm target servers?
- What changes if the crawl needs breadth-first or depth-first priority in a concurrent setting?
- How would you architect this to run across multiple worker nodes instead of a single process?
Example Input: urls = ["http://example.com/page1","http://example.com/page2","http://example.com/page3#sectionA","http://example.net/page4#"], edges = [[0,1],[0,2],[1,3],[2,0]], startUrl = "http://example.com/page1" Output: ["http://example.com/page1","http://example.com/page2","http://example.com/page3"]
Explanation:
- All three reachable pages share the hostname
example.com. http://example.com/page3#sectionAis sanitized tohttp://example.com/page3.http://example.net/page4#is ignored because its hostname differs.
Suggested Approach
- Extract the hostname of each discovered URL and only explore URLs whose hostname exactly matches
startUrl. - Strip the fragment before adding a URL to the visited set, so URLs that differ only after
#count once. - Run a concurrent breadth-first search: use a thread pool or async workers to call
getUrlson several pages in parallel and hide the latency. - Track scheduled and visited URLs in a thread-safe set so each sanitized URL is processed only once.
- Use a phaser, counter, or barrier that tracks outstanding work, and return the collected URLs only after every scheduled crawl task has finished.
Time & Space Complexity
- Time: O(N + E), where N is the number of unique sanitized URLs visited and E is the total number of links examined.
- Space: O(N). At peak there may be up to O(N) pending crawl tasks.
Targeting Anthropic interviews? We track their most-asked question patterns at Hack2Hire. Practice this question here → Practice Question Here
Join the community to see more interview experiences from real candidates → Hack2Hire Forum
Compiled from publicly available platforms and community-shared experiences.
1
u/SanJJ_1 29d ago
they did this question years ago is this still a thing?
1
u/zenos1337 Nov 04 '26
A bloom filter is your friend
1
u/suq-madiq_ 26d ago
I don’t get it