← Questions

Match people to questions using tags and priorities

0
GoogleCodingLast asked Dec 2025

A coding interview question asked in Google's first round (coding), last asked Dec 2025. It tests graphs, matching and greedy.

A help forum routes questions to people who can answer them. Each person has a set of skill tags and a capacity, the most questions they can take. Each question has a set of tags and a priority. A person can take a question when they share at least one tag with it. Assign questions to people so that higher-priority questions are served first: the set of assigned questions should be the best possible when compared priority by priority, and nobody goes over capacity.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • assign(people: dict[str, tuple[list[str], int]], questions: list[tuple[str, list[str], int]]) -> dict[str, str] — people maps a name to (tags, capacity); each question is (id, tags, priority); returns question id to person for the assigned questions. A higher number is a higher priority; ties go to the smaller id.

Example

people    = {"ana": (["python", "ml"], 1), "raj": (["python"], 1)}
questions = [("q1", ["python"], 3), ("q2", ["ml"], 2)]

assign(people, questions)  ->  {"q1": "raj", "q2": "ana"}
# a greedy pass gives q1 to ana (the first fit), then q2 has no one left;
# moving q1 to raj frees ana for q2

Constraints

  • Up to a few thousand people and questions; tags per item are few.

Clarifying questions

  • Does a person need one shared tag, or all of the question's tags?
  • Must every high-priority question be served before any lower one, or is it a weighted total?
  • Can a question go to several people?
  • Is this a one-off batch, or do questions arrive continuously?

What a strong answer covers

  • Modelling it as bipartite matching between questions and capacity slots of people (or a flow network with person capacities).
  • Processing questions in priority order and adding each through an augmenting path (Kuhn's algorithm), which can move earlier questions to other people but never drops one. This greedy is optimal because the sets of questions that can be served together form a matroid.
  • Complexity: O(Q · E) for simple augmenting paths; Hopcroft-Karp or max-flow for larger inputs.
  • An index from tag to people so eligibility checks are fast.
  • When a plain greedy pass is enough (for example, when every question has one tag) and when it is not, shown by the example.

Follow-ups

  • Prefer the person with the best tag overlap or the lightest load among valid choices.
  • Questions arrive in real time and must be assigned at once (online matching).
  • Some people are unavailable at certain times.

Where it's asked

  • Google · First round: coding · Last asked Dec 202545 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI

What it tests

graphs · matching · greedy

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding