Implement crawler and bracket validator
Company: Snowflake
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Implement two tasks:
(
1) Write a function crawl(start_urls, fetch, max_depth, domain_filter) that visits pages starting from the given seed URLs using the provided fetch(url) -> (content, outgoing_links) API. Requirements: avoid revisiting URLs (handle cycles), support breadth-first traversal limited by max_depth, enforce domain_filter, and return the set of discovered URLs. Analyze time and space complexity.
(
2) Design an algorithm to validate whether a string of parentheses is well-formed. Extend it to support three bracket types '()', '[]', and '{}', and return the index of the first error if invalid. Discuss complexity and edge cases (e.g., empty string, odd length, early closing).
Quick Answer: This question evaluates competencies in web crawling and string validation, covering graph traversal and cycle avoidance with domain filtering for crawl discovery, and delimiter matching with error indexing for multi-type bracket validation.