skip to content

questions

24

In a document tag filter, which set operation returns documents tagged either label, and which returns documents tagged both?

level: juniorimportance: must knowfreq 72%

answer

  1. a label names a set of documents
  2. one filter widens, the other narrows
  3. or here is inclusive, never exclusive
  4. at least one versus every operand
  5. check the empty selection case

basics

~20 s

Union gives 'either' — every document carrying at least one of the labels. Intersection gives 'both' — only documents carrying every selected label. As a user ticks more labels a union can only stay the same or grow; an intersection can only stay the same or shrink.

solid answer

~50 s

Model each label as the *set of documents carrying it*: `A` is everything tagged `invoice`, `B` everything tagged `paid`. 'Tagged either' is the **union** `A ∪ B` — a document qualifies if it is in `A`, in `B`, or in both, because the 'or' of set algebra is inclusive, never exclusive. 'Tagged both' is the **intersection** `A ∩ B`, which requires membership in every operand. The consequence that matters in a product is that the two move in opposite directions: adding another label to a union can only keep the result the same size or enlarge it, while adding one to an intersection can only keep it the same or shrink it. Both operations are commutative and associative, so the order the user ticks the boxes cannot change the result set — only the wording of the filter can.

go deeper

for a junior

Know which word maps to which operation: 'any' is union, 'all' is intersection, 'but not' is difference. Be able to say which filter widens and which narrows as more labels are selected.

for a middle

Explain the monotonicity bounds and the identities behind them — commutativity, associativity, idempotence, absorption — and why they let an engine reorder the operands without changing the answer.

for a senior

Show you have specified the edges: empty selection, an unused label, a duplicated label in the request. Say which convention your product ships and where that is written down.

for a principal

Whether the default filter is 'any' or 'all' changes result sizes by orders of magnitude and changes what users believe the product does. Own that as a contract decision, not as an implementation detail each surface re-decides.

## Model a label as a set of documents The first move is a change of viewpoint, and everything else follows from it. The obvious mental model is 'a document has a list of tags'. The useful one is the dual: **each label names the set of documents that carry it**. Let `A` be the set of documents tagged `invoice` and `B` the set tagged `paid`. Every filter a user can build from those two checkboxes is now an expression in set algebra over `A` and `B`, and questions like 'what does this return?' and 'how big can it get?' become algebra instead of guesswork. The collection everything is drawn from — the whole corpus — is the **universe**, written `U`. Every set in play is a subset of `U`. ## The three operations a filter is built from - **Union** `A ∪ B` — every document that is in `A`, in `B`, or in both. This is the *inclusive* or. A document tagged both labels is in the union, and it is in it exactly once. This implements 'match any of the selected tags'. - **Intersection** `A ∩ B` — only the documents that are in `A` **and** in `B`. This implements 'match all of the selected tags'. - **Difference** `A \ B` — the documents in `A` that are not in `B`: 'tagged invoice but not paid'. | The user sees | The expression | What it does as more labels are ticked | |---|---|---| | Match any of these tags | `A ∪ B ∪ C` | stays the same or grows | | Match all of these tags | `A ∩ B ∩ C` | stays the same or shrinks | | Tagged this but not that | `A \ B` | shrinks as the excluded side grows | ## Why the direction of movement matters The two operations are **monotone in opposite directions**, and that single fact explains most filter bugs that reach a bug tracker: 1. A union is bounded below by its biggest operand: `|A ∪ B| ≥ max(|A|, |B|)`. Ticking another label can never remove a document that already matched. 2. An intersection is bounded above by its smallest operand: `|A ∩ B| ≤ min(|A|, |B|)`. Ticking another label can never add a document that did not already match. 3. Neither is *strict*. If every document tagged `paid` is also tagged `invoice`, then `A ∪ B = A` and `A ∩ B = B`: the result does not move at all. 'Can only stay the same or grow' is the honest statement; 'always grows' is not. So a screen whose result count goes **up** when a user adds a restriction is telling you the filter is a union where the copy promises an intersection, or the reverse. Exact sizing of a union of many overlapping label sets is a separate problem with its own machinery; the bounds above are all you need to sanity-check a filter. ## The identities you are allowed to lean on These hold for any sets, and query planners rely on them: - **Commutative**: `A ∪ B = B ∪ A`, `A ∩ B = B ∩ A`. The order the user clicks does not matter. - **Associative**: `(A ∪ B) ∪ C = A ∪ (B ∪ C)`. Grouping does not matter, so an engine may combine the cheapest pair first. - **Idempotent**: `A ∪ A = A`, `A ∩ A = A`. A duplicated label in the request is harmless. - **Distributive**: `A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)`. 'Invoices that are paid or overdue' can be evaluated either way round. - **Identity and annihilator**: `A ∪ ∅ = A`, `A ∩ U = A`, `A ∩ ∅ = ∅`, `A ∪ U = U`. - **Absorption**: `A ∪ (A ∩ B) = A`. Adding a narrower condition to a union changes nothing. Together these say a filter is *not* a sequence of steps whose order the user controls; it is an expression whose value is fixed by which labels were chosen and which connective the product uses. ## The edge case interviewers actually push on What should the filter return when **no labels are selected**? Set algebra gives a clean answer, and it is different for the two connectives: a union over an empty family of sets is the empty set, while an intersection over an empty family is the whole universe — every document vacuously satisfies 'all zero of these labels'. Most products therefore show the whole corpus for an empty selection, which is the intersection convention, even when the filter itself is an 'any of these' union. That is a deliberate choice, not a derivation, and it belongs in the contract rather than in whichever branch the code happened to take. The second edge is a label nobody uses: its set is `∅`, so it is invisible in a union and catastrophic in an intersection, where it empties the result. A filter that silently returns nothing after a typo in a label name is this rule firing exactly as specified.

  • What should the filter return when the user has selected no labels at all?
    Algebraically the two connectives disagree: a union over an empty family is the empty set, an intersection over an empty family is the whole universe, because every document vacuously carries all zero labels. Most products show everything, which follows the intersection convention. The point is that it is a stated product choice, not an accident of which loop the code runs.
  • A user ticks a label that no document carries. What happens to each kind of filter?
    That label's set is empty. In a union it changes nothing, since the empty set is the identity for union. In an intersection it wipes the result out, since intersecting with the empty set gives the empty set. A filter that suddenly returns zero results after one extra tick is usually this, most often caused by a mistyped or newly renamed label.
  • Why may a query planner evaluate 'tagged all of X, Y and Z' in whatever order it likes?
    Intersection is commutative and associative, so every grouping and ordering of the three sets yields the same set. That freedom lets an engine start with the smallest label set and shrink the working set as fast as possible. It is a performance choice with no effect on the answer, which is exactly what those two identities guarantee.

saying these in an interview costs you the question

  • Reads 'tagged either label' as excluding documents that carry both.
  • Expects an 'any of these tags' filter to narrow as more labels are ticked.
  • Says an intersection can be larger than the smaller of its two inputs.
  • Believes the order the user selects labels changes the result set.
  • Assumes a document tagged both labels appears twice in the union.
  • Claims adding a label to a union must strictly increase the result.
open as a page

A merge pipeline buckets rows by a grouping key: what must that key's equality and its hash satisfy for lookups to stay correct?

level: middleimportance: must knowfreq 72%

basics

~20 s

Equality must be an equivalence relation — reflexive, symmetric, transitive — and must stay stable while the key is stored. Equal keys must produce equal hashes; unequal keys are allowed to collide, and a collision never means equality.

open as a page

A merge pipeline groups customer rows by a 'same person' rule: which three properties must that rule satisfy for the groups to be well defined?

level: middleimportance: must knowfreq 64%

basics

~20 s

Reflexivity, symmetry and transitivity. A rule with all three is an equivalence relation, and only then does it cut the rows into disjoint groups where every row lands in exactly one group, whichever row you start from.

open as a page

A migration remaps every old record identifier to a new one: what does injectivity of that mapping guarantee, and what breaks without it?

level: middleimportance: must knowfreq 66%

basics

~20 s

Injective means no two distinct old identifiers are sent to the same new identifier. Lose it and two separate records land on one row in the target: one write overwrites the other, references converge, and no rollback can tell them apart.

open as a page

When does a remapping from old record identifiers to new ones have an inverse that translates any new identifier back?

level: middleimportance: must knowfreq 54%

basics

~20 s

Injectivity alone gives an inverse only on the identifiers the remap actually produced. To translate back any identifier the new store holds, the remap must also be surjective onto that set — together, a bijection onto it.

open as a page

Why is the 'happened before' relation on a replicated log's events a partial order rather than a total order?

level: middleimportance: must knowfreq 66%

basics

~20 s

Happened-before relates only events that are causally linked. If neither event saw the other, they are incomparable, not equal. A partial order permits such incomparable pairs; a total order demands that every pair be comparable.

open as a page

A tag filter excludes documents tagged draft or internal — which set expression over the two label sets is equivalent, and why?

level: middleimportance: must knowfreq 55%

basics

~20 s

The intersection of the two exclusions: documents that are not draft AND not internal. De Morgan's law for sets says the complement of a union is the intersection of the complements, so negating the filter flips 'or' into 'and'.

open as a page

Why does a sort comparator that reports 'equal' for two incomparable items corrupt the result rather than merely ordering them arbitrarily?

level: seniorimportance: must knowfreq 56%

basics

~20 s

Sorting assumes a total order. Reporting 'equal' for incomparable items breaks transitivity, so the comparator contradicts itself: the output can be genuinely unsorted rather than arbitrarily tied, and some sort routines detect the contradiction and fail outright.

open as a page

Why can the old store's row count be the new store's row count only when the remapping between them is a bijection?

level: middleimportance: should knowfreq 40%

basics

~20 s

A one-sided map gives only an inequality. An injection from old rows into new ones proves the old count is at most the new; a surjection proves it is at least. Only a bijection, both at once, gives equality.

open as a page

What separates a maximal version from a maximum version in a store ordered by 'is an ancestor of'?

level: middleimportance: should knowfreq 46%

basics

~20 s

A maximal version has nothing above it. A maximum version is above everything. A store can hold several maximal versions at once — concurrent heads — but a maximum, when one exists, is unique and dominates every other version.

open as a page

A pipeline de-duplicates a stream of label occurrences into a set — which queries does that silently change the answer to?

level: middleimportance: should knowfreq 46%

basics

~20 s

Every query that depends on how often something occurred: totals, averages, and any ranking by popularity. Membership questions survive de-duplication untouched, because a set records only whether an element is present, while a multiset also records how many times.

open as a page

A document may carry any combination of n labels — how many distinct label sets exist, and what does that rule out?

level: middleimportance: should knowfreq 50%

basics

~20 s

There are 2^n of them — the power set of the label set, including the empty combination. Because the count doubles with every label added, precomputing or caching one entry per possible label-set filter is impossible past roughly twenty labels.

open as a page

A 'same customer' rule matches names within one edit, so Jon matches Jan and Jan matches Ian: what breaks when you group with it?

level: seniorimportance: should knowfreq 55%

basics

~20 s

The rule is reflexive and symmetric but not transitive, so it has no equivalence classes. 'The group of a row' stops being a property of the data and becomes a property of the traversal order, and chains of near matches fuse distinct people.

open as a page

A matcher emits only direct 'same entity' pairs between customer rows: what does the transitive closure of those pairs give you?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The smallest transitive relation containing every reported pair: two rows are related when a chain of reported pairs links them. Closing reflexively and symmetrically too gives the smallest equivalence containing the pairs, which is the grouping the matcher implies.

open as a page

Why can no scheme assign a distinct finite identifier to every infinite stream of events a system could emit?

level: seniorimportance: should knowfreq 34%

basics

~20 s

Finite identifiers can be listed one after another, so they reach only countably many things. The infinite streams are uncountable: given any listing, flip the n-th symbol of the n-th stream and you have built a stream the listing missed.

open as a page

What does the join of two permission sets in a lattice give you that a plain partial order cannot?

level: seniorimportance: should knowfreq 38%

basics

~20 s

The join is the least upper bound: the smallest level that dominates both, unique whenever it exists. A plain partial order may offer several incomparable upper bounds, or none at all, so 'combine these two' has no canonical answer there.

open as a page

Why can two services that both implement 'documents not tagged archived' return different documents for the same corpus?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Because a complement is meaningless until its universe is fixed. 'Not tagged archived' names a set only relative to a chosen collection — the whole corpus, one tenant, one shard, or the current page — and two services that pick different universes implement different filters.

open as a page

A near-match matcher can never be made transitive without fusing distinct people: how should the platform define what 'same customer' means?

level: principalimportance: should knowfreq 34%

basics

~20 s

Keep two relations. Identity is defined so that it is an equivalence by construction — equality of a normalized key — and the near-match rule stays advisory, feeding review and search but never partitioning the data or naming anything other systems store.

open as a page

How do you decide whether a store migration's identifier remapping must be an invertible bijection rather than a deliberate many-to-one merge?

level: principalimportance: should knowfreq 28%

basics

~20 s

Decide by who still holds the old identifiers and what must be answerable later. A merge is a one-way loss of injectivity: the inverse stops existing, and only preimages you deliberately store can answer lineage questions afterwards.

open as a page

When is forcing one linear extension of an event order the right design, and when must the partial order survive?

level: principalimportance: should knowfreq 33%

basics

~20 s

A linear extension is a total order that agrees with the partial one, and a partial order usually admits many. Choosing one buys a single replayable sequence; it also erases which events were concurrent, which is precisely what conflict detection needs.

open as a page

A merged customer group must expose one stable identifier: what property must the choice of canonical representative have?

level: seniorimportance: nice to knowfreq 30%

basics

~20 s

The representative must be determined by the class's members alone — never by arrival order, worker or wall-clock time. Formally it is a function whose value is equal for two rows exactly when they are in the same class.

open as a page

If two identifier-remapping stages run in sequence and the combined mapping is injective, what does that prove about each stage?

level: seniorimportance: nice to knowfreq 24%

basics

~20 s

Only the first stage must be injective. The second may collide freely outside the first stage's image, because the composition never exercises it there — which is a live defect the moment anything else feeds the second stage directly.

open as a page

What does the largest antichain of a 'must finish before' order over tasks tell you about that workload?

level: seniorimportance: nice to knowfreq 27%

basics

~20 s

The largest antichain is the order's width: the greatest number of tasks that are pairwise unordered, and therefore a ceiling on how many could ever be in flight together. Dilworth's theorem says that same number is the fewest chains needed to cover every task.

open as a page

An optimized tag filter is claimed to return exactly the documents the brute-force one does — what does an argument by mutual inclusion give you that spot-checks do not?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

Coverage of every input rather than the sampled ones. Two sets are equal exactly when each contains the other, so arguing both directions over an arbitrary document rules out both failure modes — missing results and extra ones — while a spot-check only shows the cases you happened to pick.

open as a page