Yelp software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
[a, b] meaning task a is blocked by task b (i.e., a must wait for b). Each task blocks at...Input: Graph (nodes and edges)doc1 and doc2, compute their word-level Jaccard similarity. Split each title into words by spaces and treat each...Input: Strings1 and s2, merge them by finding the longest suffix of s1 that exactly matches a prefix of s2. Join the two...Input: StringProductSearch class for a product catalog search engine. The constructor takes a list of product names. The search(keyword) method...Input: List[agent, customer, issue]. A customer's engagement score is the number of unique agents...Input: Listk item names where at least one word in the name starts with...Input: Listsender_id, business_id, message, and minute. minute is a nonnegative integer represented as a string.RAW_COUNT: every record contributes exactly 1 to its business's received-message count, including identical records.k businesses with at least one record, ordered by received count descending, then business_id lexicographically ascending.k = 0 produces an empty leaderboard. In this stage, count the entire batch and ignore timestamps.rank_business_messages(records: list[dict[str, str]], k: int). The return type is up to you; the examples use a JSON object containing leaders.{
"records": [
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "10"},
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "11"},
{"sender_id": "u1", "business_id": "a", "message": "hours", "minute": "12"},
{"sender_id": "u2", "business_id": "b", "message": "table", "minute": "13"},
{"sender_id": "u3", "business_id": "c", "message": "menu", "minute": "14"}
],
"k": 2
}{
"leaders": [
{"business_id": "a", "received": 3},
{"business_id": "b", "received": 1}
]
}a count, including the repeated quote. Businesses b and c each receive 1 message; b wins the lexicographic tie for the second position.Part 2 — Rolling, deduplicated demand snapshotsrank_message_windows(records: list[dict[str, str]], query_times: list[str], k: int).Before implementing, discuss how your return type changes to represent multiple snapshots and explain why a single received count is no longer sufficient. Your approach must be flexible enough to support future message-equivalence policies, per-sender caps, and diagnostic rules without rewriting the window-processing engine.t, independently consider records in the exact window t - 60 < minute <= t. Input records and query times can be unsorted. Return snapshots in the original query order, including repeated query times.received remains the raw number of records for the business in that window.DEDUPLICATE: two active records represent the same unique message exactly when their sender_id, business_id, and message strings are equal. Their timestamps do not need to match. A unique message remains active until its last copy leaves the window.unique is the number of distinct messages after that deduplication. For each sender, let u be their unique-message count for that business in the window.SENDER_CAP: the sender contributes min(u, 2) to the business's score. Sum those contributions across senders.score descending, then business_id lexicographically ascending. Return at most k businesses.received, unique, score, and rules. Include DUPLICATE_MESSAGE exactly when received > unique, and SENDER_CAP exactly when unique > score. List rule names lexicographically; otherwise return an empty list.as_of, preserving the query's original string, and leaders. An empty window produces an empty leaders list.{
"records": [
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "10"},
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "11"},
{"sender_id": "u1", "business_id": "a", "message": "hours", "minute": "12"},
{"sender_id": "u1", "business_id": "a", "message": "patio", "minute": "13"},
{"sender_id": "u2", "business_id": "b", "message": "table", "minute": "14"},
{"sender_id": "u3", "business_id": "b", "message": "menu", "minute": "15"}
],
"query_times": ["15", "72"],
"k": 2
}{
"snapshots": [
{
"as_of": "15",
"leaders": [
{"business_id": "a", "received": 4, "unique": 3, "score": 2, "rules": ["DUPLICATE_MESSAGE", "SENDER_CAP"]},
{"business_id": "b", "received": 2, "unique": 2, "score": 2, "rules": []}
]
},
{
"as_of": "72",
"leaders": [
{"business_id": "b", "received": 2, "unique": 2, "score": 2, "rules": []},
{"business_id": "a", "received": 1, "unique": 1, "score": 1, "rules": []}
]
}
]
}a has 4 deliveries but only 3 unique messages from u1, so its score is min(3, 2) = 2; both diagnostics fire. Business b scores min(1, 2) + min(1, 2) = 2, and a wins the tie. At 72, the window is (12, 72]: the record at 12 is excluded, leaving only patio for a, while both records for b remain. Their scores are therefore 1 and 2.Example 3:{
"records": [
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "0"},
{"sender_id": "u1", "business_id": "a", "message": "quote", "minute": "1"},
{"sender_id": "u1", "business_id": "a", "message": "hours", "minute": "2"},
{"sender_id": "u1", "business_id": "a", "message": "patio", "minute": "3"},
{"sender_id": "u2", "business_id": "b", "message": "menu", "minute": "60"}
],
"query_times": ["60", "59", "61", "121"],
"k": 2
}{
"snapshots": [
{
"as_of": "60",
"leaders": [
{"business_id": "a", "received": 3, "unique": 3, "score": 2, "rules": ["SENDER_CAP"]},
{"business_id": "b", "received": 1, "unique": 1, "score": 1, "rules": []}
]
},
{
"as_of": "59",
"leaders": [
{"business_id": "a", "received": 4, "unique": 3, "score": 2, "rules": ["DUPLICATE_MESSAGE", "SENDER_CAP"]}
]
},
{
"as_of": "61",
"leaders": [
{"business_id": "a", "received": 2, "unique": 2, "score": 2, "rules": []},
{"business_id": "b", "received": 1, "unique": 1, "score": 1, "rules": []}
]
},
{"as_of": "121", "leaders": []}
]
}a has 4 deliveries, 3 unique messages, and score min(3, 2) = 2, triggering both rules. At 60, the copy at minute 0 expires, but the copy at minute 1 keeps quote active: received = unique = 3, while the score remains 2. At 61, the last quote copy expires, giving received = unique = score = 2. The record at minute 60 is included at times 60 and 61, but excluded at 121. Despite processing times chronologically internally, return snapshots in the requested order.Notes:0 <= k <= 200,000. The total number of returned leaderboard entries is at most 200,000.strings (user reviews) and an integer n as input and returns a dictionary where the keys are n-grams of size n and the values are their corresponding counts. An n-gram is a contiguous sequence of n items (words) from the text.def count_ngrams(reviews: List[str], n: int) -> Dict[str, int]:reviews = ["The food was great", "Great place for food"], n = 2 {'The food': 1, 'food was': 1, 'was great': 1, 'Great place': 1, 'place for': 1, 'for food': 1} reviews = ["Good ambiance, good food", "Good service"], n = 3 {'Good ambiance, good': 1, 'ambiance, good food': 1, 'good food Good': 1, 'Good service': 1} length of reviews <= 10^4 n <= 10 reviews where each review is a string of words, and an integer N, write a function to return a list of the top N most common keywords. Keywords should be considered case-insensitive and you may ignore common stop words like 'the', 'is', 'in', etc.def top_n_keywords(reviews: List[str], N: int) -> List[str]:reviews = ["Great service and food", "Good food but slow service", "Great ambiance and service"], N = 2 ['service', 'food'] reviews = ["Best coffee ever", "This coffee is great", "Excellent coffee and tea"], N = 1 ['coffee'] Constraints: n items from a given sample of text. Your function should ignore punctuation and be case-insensitive, returning all unique n-grams sorted in alphabetical order.Function/class signature:def find_ngrams(text: str, n: int) -> List[str]:text = "The food is great and the service is excellent", n = 2 ["and the", "excellent", "food is", "great and", "is great", "is excellent", "service is", "the food"] text = "Yelp is a service to find great food", n = 3 ["a service to", "find great food", "great food", "is a service", "to find great"] 1 <= n <= 10 0 <= len(text) <= 10^5 ratings representing the ratings provided by users, you want to find the maximum sum you can form by choosing elements in a way that no two elements chosen can be adjacent in the original order. You must ensure to select the elements such that the chosen subarray does not include adjacent indices. def max_rating_sum(ratings: List[int]) -> int: ratings = [3, 2, 5, 10, 7] 15 3 (index 0), 10 (index 3), and 2 (index 1) giving a total of 3 + 10 +2 = 15. ratings = [1, 2, 3, 1] 4 2 (index 1) and 1 (index 3) yielding 2 + 1 = 3. 0 <= len(ratings) <= 1000 0 <= ratings[i] <= 1000 reviews (strings) and an integer n, implement a function to find all n-grams (consecutive sequences of n words) from the reviews. The output should be a list of strings representing these n-grams.Function/class signature:def find_ngrams(reviews: List[str], n: int) -> List[str]:reviews = ['The food was great', 'Great service and great ambiance'], n=2 ['The food', 'food was', 'was great', 'Great service', 'service and', 'and great', 'great ambiance'] reviews = ['Loved the pizza', 'Pizza was too salty'], n=3 ['Loved the pizza', 'the pizza was', 'pizza was too', 'was too salty'] len(reviews) <= 100 len(reviews[i]) <= 1000 n <= 10 def find_duplicate_reviews(reviews: List[str]) -> List[str]:['Great food!', 'Great food! ', 'Nice service', 'Great food!'] ['Great food!'] ['Excellent place', 'Excellent Place', 'Not bad', 'liked it'] [] Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free