Web Crawler Multithreaded — LeetCode 1242 Python Solution

MediumLeetCode PremiumDepth-First SearchBreadth-First SearchConcurrency
Problem
#1242
Reading time
2 min

The problem

Given a URL startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl. Return all URLs obtained by your web crawler in any order.

Example

interface HtmlParser {
  // Return a list of all urls from a webpage of given url.
  // This is a blocking call, that means it will do HTTP request and return when this request is finished.
  public List<String> getUrls(String url);
}

Complexity

MeasureComplexity
TimeO(V+E)
SpaceO(V) auxiliary

Pattern: Breadth-First Search

Expand outward level by level, so the first time you arrive is the shortest way. LeetCode 1242. Web Crawler Multithreaded is filed here because LeetCode tags it Breadth-First Search, which is the vocabulary this hub collects.

The breadth-first search guide has the Python template for the pattern and the 233 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 1242. Web Crawler Multithreaded?
LeetCode 1242. Web Crawler Multithreaded is rated Medium on LeetCode.
What is the time complexity of LeetCode 1242. Web Crawler Multithreaded?
The Python solution on this page runs in O(V+E).
What is the space complexity of LeetCode 1242. Web Crawler Multithreaded?
The Python solution on this page uses O(V) auxiliary space.
What topics does LeetCode 1242. Web Crawler Multithreaded cover?
LeetCode 1242. Web Crawler Multithreaded is tagged Depth-First Search, Breadth-First Search and Concurrency on LeetCode.
Is LeetCode 1242. Web Crawler Multithreaded a premium problem?
Yes. LeetCode 1242. Web Crawler Multithreaded is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview