Reddit software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
id and...Input: Listrelationships, where each element is a list of strings. The first string represents a...Input: Array of stringsSystem Design Questions - Reddit These are the most commonly asked system design questions from Reddit interviews.
Input: Number(s)s, return the length of the longest substring without repeating characters. A substring is defined as a contiguous sequence of characters in s. You must implement an efficient solution to handle potentially large strings common in user-generated content.def length_of_longest_substring(s: str) -> int: "abcabcbb" 3 "abc", with the length of 3."bbbbb" 1 "b", with the length of 1.s consists of English letters, digits, symbols and spaces.RateLimiter class that supports multiple APIs and handles different request quotas per user efficiently. Each user has a unique ID and can have different rate limits on different APIs. Your implementation should allow checking if a user can make a request to an API and register the request, updating the rate limit accordingly.class RateLimiter def can_request(self, user_id: str, api_name: str) -> bool: def register_request(self, user_id: str, api_name: str) -> None:rate_limiter = RateLimiter() rate_limiter.register_request('user1', 'api1') rate_limiter.can_request('user1', 'api1') True rate_limiter.register_request('user1', 'api1') rate_limiter.register_request('user1', 'api1') rate_limiter.can_request('user1', 'api1') False RateLimiter class.PriorityQueue class that supports adding threads with a given priority and returning the thread with the highest priority. The class should implement the following operations: add(thread: str, priority: int) -> None: Inserts a new thread with the specified priority into the priority queue. poll() -> str: Removes and returns the thread with the highest priority. If two threads have the same priority, return the one that was added first. peek() -> str: Returns the thread with the highest priority without removing it from the queue. class PriorityQueue: def add(self, thread: str, priority: int) -> None: def poll(self) -> str: def peek(self) -> str: Example 1: pq = PriorityQueue() pq.add("Post A", 2) pq.add("Post B", 3) pq.poll() "Post B" pq = PriorityQueue() pq.add("Post X", 1) pq.add("Post Y", 1) pq.poll() "Post X" longest_path(graph: Dict[int, List[int]], start: int) -> int where graph is a dictionary where each key represents a node and the value is the list of nodes it points to. def longest_path(graph: Dict[int, List[int]], start: int) -> int:graph = {1: [2, 3], 2: [4], 3: [], 4: []}, start = 13graph = {1: [2], 2: [3], 3: [4], 4: []}, start = 14add_api(api_name: str, quota: int) -> None: Adds a new API with its request quota.can_request(user_id: str, api_name: str) -> bool: Checks if the user can make a request to the given API.record_request(user_id: str, api_name: str) -> None: Records a request made by the user to the given API.reset_user_quota(user_id: str, api_name: str) -> None: Resets the user's quota after a designated time interval.add_api("getComments", 100) → Output: None → Explanation: A new API with a quota of 100 requests has been added.can_request("user123", "getComments") → Output: True → Explanation: User can make a request as they haven't exceeded the quota.record_request("user123", "getComments") → Output: None → Explanation: Request recorded.can_request("user123", "getComments") → Output: True/False → Explanation: Depending on the number of recorded requests.RateLimiter class should handle different quotas for each user per API efficiently.def set_limit(user_id: str, api_name: str, limit: int, period: int) -> None: Sets the rate limit for a particular user on a specific API. def can_request(user_id: str, api_name: str) -> bool: Checks if a user can request an API call without exceeding the limit. def record_request(user_id: str, api_name: str) -> None: Records an API request for a user. def reset_usage(user_id: str, api_name: str) -> None: Resets the usage for a user on a specific API after the defined period.set_limit('user123', 'api1', 5, 60) record_request('user123', 'api1') can_request('user123', 'api1') True set_limit('user123', 'api1', 2, 30) record_request('user123', 'api1') record_request('user123', 'api1') can_request('user123', 'api1') False Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free