MediumNo. 1242LeetCode Premium
Web Crawler Multithreaded — LeetCode 1242 Python Solution
- Pattern
- Breadth-First Search
- Topics
- Depth-First Search, Breadth-First Search, Concurrency
- Reading time
- 2 min
- Source
- leetcode.com
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
- Time
- O(V+E)
- Space · auxiliary
- O(V)
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
| No. | Problem | Difficulty |
|---|---|---|
| 0100 | Same Tree | Easy |
| 0101 | Symmetric Tree | Easy |
| 0104 | Maximum Depth of Binary Tree | Easy |
| 0111 | Minimum Depth of Binary Tree | Easy |
| 0112 | Path Sum | Easy |
| 0116 | Populating Next Right Pointers in Each Node | Medium |
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.