Category: Grid/matrix coding problemYou are given an m x n binary grid where each cell is either '1' (land) or '0' (water). A group of connected land cells (connected horizontally...Input: 2D grid Output: Computed result
codingMediumVerified Question#2
2. Parallel Task Batching
Category: Graph coding problemA pipeline must execute a set of tasks with dependency constraints. Each dependency [A, B] means task A must complete before task B can start....Input: Graph (nodes and edges) Output: Computed result
codingMediumVerified Question#3
3. Island Statistics
Category: Grid/matrix coding problemYou are given an m x n binary grid where '1' is land and '0' is water. For each island (a connected group of land cells using horizontal and...Input: 2D grid Output: Array
codingMediumVerified Question#4
4. Unfriended Pairs Counter
Category: Algorithm coding problemIn a social network of n people labeled 0 to n - 1, friendship is mutual and transitive through direct connections. People belong to the same...Input: List Output: Computed result
codingHardVerified Question#5
5. Expression Calculator
Category: String coding problemImplement a calculator that evaluates a mathematical expression given as a string s. The expression may contain positive and negative integers, the...Input: String Output: Computed result
codingHardVerified Question#6
6. Prime Subset Products
Category: Array coding problemGiven an array primes where every element is a prime number (duplicates are allowed), find all distinct products that can be formed by multiplying...Input: Array Output: Computed result
codingMediumVerified Question#7
7. Peak Attendance Finder
Category: Interval-based coding problemYou are organizing an event. Each attendee's presence is described by a half-open interval [entry, exit), meaning they are present at every integer...Input: List Output: Integer
codingMediumVerified Question#8
8. Org Chart Builder
Category: String coding problemA company has a list of employees. Each entry has three strings: [id, manager_id, name]. The CEO is the only employee whose manager_id equals...Input: List Output: Computed result
codingMediumbinary search#1
1. Binary Search — Find a User by Username
1. Background: In Snapchat, users often search for friends by their username. Efficiently locating users in a vast database is crucial to provide a smooth user experience and maintain engagement. 2. Problem statement: Given a sorted list of unique usernames and a target username, return the index of the target username in the list. If the username does not exist, return -1. Implement a function using binary search to optimize the search efficiency. 3. Function signature: def find_username(usernames: List[str], target: str) -> int 4. Example 1: Input: usernames = ['alice', 'bob', 'charlie', 'dave'], target = 'charlie' Output: 2 Explanation: The username 'charlie' is found at index 2. 5. Example 2: Input: usernames = ['alice', 'bob', 'charlie', 'dave'], target = 'eve' Output: -1 Explanation: The username 'eve' is not in the list. 6. Constraints: - 1 <= len(usernames) <= 10^4 - Each username has at most 100 characters, containing only lowercase letters and numbers.
codingMediumhash map#2
2. [Hash Map] — Implement a user status checker for Snapchat
Background: Snapchat frequently updates user statuses, which can be seen by friends. Implementing a system to efficiently check the status of multiple users is essential to enhance user engagement and ensure the app runs smoothly. Problem statement: You need to design a function that takes a list of user IDs and returns their current status from a predefined mapping of user statuses. The function should handle requests efficiently, especially when the same user ID is checked multiple times. Specifically, if the user ID does not exist in the mapping, return "unknown". Function/class signature:
Explanation: user3 is not in the mapping, while user4 is active.
Constraints:
1 <= len(user_ids) <= 10^4
1 <= len(user_status) <= 10^4
User IDs consist of alphanumeric characters and underscores only.
If a user ID is checked multiple times, you can expect the check to be performed efficiently.
codingMediumgraph#3
3. [Graph] — Implement a Friend Suggestion Algorithm
Background: In Snapchat, users send snaps to friends, and often inquire about friends-of-friends to expand their network. A key feature is suggesting new friends based on existing connections. Problem statement: Given a list of users and their friend connections, implement a function that returns a list of suggested friends for a given user. Friend suggestion examines friends-of-friends and excludes those already connected to the user. The result should prioritize suggestions by the number of mutual friends shared with the user. Function/class signature:
Explanation: Bob has mutual connections with Charlie and Eve that are not his direct friends.
Constraints:
1 ≤ number of connections ≤ 10^5
Each user name is at most 50 characters long
Connections are undirected; each pair (a, b) implies both a is a friend of b and vice versa.
codingMediumtwo pointers#4
4. [Two Pointers] — Finding the Optimal Snap Filters
Background: Snapchat uses a variety of filters to enhance user engagement. To suggest optimal filters based on user preferences and photo characteristics, a two-pointer approach can help identify compatible filters quickly. Problem statement: You are given two sorted lists of filters and user preferences. Each filter has a rating and each user preference specifies a desired rating range. Your task is to find the maximum number of filters that fit within the user's desired ratings while ensuring each filter is only used once. Return the total count of usable filters. Function/class signature:
5. Graph Traversal — Finding Users in a Snapchat Group
Background: Snapchat allows users to create groups where they can interact with multiple friends at once. For features like notifications or updates, it's important to quickly identify users in a group. This problem relates to the social graph architecture used by Snapchat to model users and connections. Problem statement: Given a list of users represented as a graph where each user is a node and friendships are edges, write a function that finds all user IDs in a group by performing a breadth-first search (BFS) starting from a given user ID. The function should return the user IDs of all reachable friends within k steps. Function/class signature:
Example 1: Input: graph = {1: [2, 3], 2: [1, 4], 3: [1], 4: [2]}, start_user = 1, k = 2 Output: [1, 2, 3, 4] Explanation: From user 1, within 2 steps, all users 2, 3, and 4 are reachable.Example 2: Input: graph = {1: [2], 2: [1, 3], 3: [2], 4: []}, start_user = 2, k = 1 Output: [2, 1, 3] Explanation: From user 2, within 1 step, users 1 and 3 are reachable.Constraints:
All user IDs are unique integers.
The graph may contain up to 10^5 users.
0 <= k <= 10^5.
The graph is undirected and may contain cycles.
codingMediumsliding window#6
6. CODING — Longest Unique Substring Finder
1. Background: Snapchat frequently deals with media messaging, where users can send images, videos, and messages that often contain unique identifiers or metadata. An efficient way of allowing users to search through their messages is to keep track of unique content. 2. Problem statement: Given a string s, your goal is to find the length of the longest substring that does not contain any repeated characters. This challenge is critical for Snapchat as it could relate to efficiently managing and displaying unique identifiers in user-generated content across the platform. 3. Function/class signature: - def longest_unique_substring(s: str) -> int: 4. Example 1: - Input: "abcabcbb" - Output: 3 - Explanation: The longest substring without repeating characters is "abc", which has length 3. 5. Example 2: - Input: "bbbbb" - Output: 1 - Explanation: The longest substring without repeating characters is "b", which has length 1. 6. Constraints: - 0 <= s.length <= 1000 - s consists of English letters, digits, symbols, and spaces.
Start practicing Snapchat questions
Sign up for free to access walkthroughs, AI-generated questions, and more.