Yelp software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
sender_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.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free