Yelp logo

Yelp Hard Interview Questions

3 hard-level practice questions for Yelp technical interviews

Yelp software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Phrase Tokenizer


Category: String coding problem
Given a string of space-separated words and a dictionary of recognized phrases, split the string into tokens. Phrases in the dictionary represent...
Input: String
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Yelp questions with AI.
Sign up free
coding Hard Verified Question #2

2. Conference Buddy Pairing


Category: String coding problem
You are organizing a conference and want to pair up attendees as buddies. Each attendee belongs to a department.
Input: Array of pairs
Output: Integer
coding Hard heap #1

1. [AI Enabled Coding] Business Messaging Demand Leaderboard


Yelp connects consumers with local businesses through messaging and quote requests. In this exercise, build an internal leaderboard that helps operations teams identify businesses receiving the most messages, then extend it so repeated message deliveries and bursts from one consumer do not inflate the demand signal. You may use an AI assistant while coding, but you are responsible for validating its design and results; the scoring policies below are exercise assumptions, not claims about Yelp's production policies.
Part 1 — Raw message leaderboard
  • Each record has exactly four string-valued fields: 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.

  • Return at most 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.

  • Implement 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.


Example 1:
Input:
{
  "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
}

Output:
{
  "leaders": [
    {"business_id": "a", "received": 3},
    {"business_id": "b", "received": 1}
  ]
}

Explanation: All three records for 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 snapshots
Operations now needs many historical snapshots, with a demand score resistant to repeated deliveries and sender bursts. Preserve Part 1's behavior and add rank_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.
  • For each query time 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.

  • Rank businesses with at least one active record by score descending, then business_id lexicographically ascending. Return at most k businesses.

  • For each returned business, include 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.

  • Each snapshot includes as_of, preserving the query's original string, and leaders. An empty window produces an empty leaders list.

  • Do not rescan all records or sort all active businesses for every query. Design for large batches and a small total requested output.


Example 2:
Input:
{
  "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
}

Output:
{
  "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": []}
      ]
    }
  ]
}

Explanation: At 15, 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:
Input:
{
  "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
}

Output:
{
  "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": []}
  ]
}

Explanation: At 59, 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:
  • There are at most 200,000 records and 200,000 queries; 0 <= k <= 200,000. The total number of returned leaderboard entries is at most 200,000.

  • Inputs satisfy the schema. IDs are nonempty ASCII strings; messages use exact, case-sensitive string equality. Integer minute values are between 0 and 1,000,000,000.

  • Work in memory on a complete batch. Distributed execution, persistence, and concurrent updates are out of scope.
Want to practise this one?
Create a free account to open the full question and practise Yelp questions with AI.
Sign up free

Start practicing Yelp questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free