skip to content

A widening finds two rows supplying the same cell — what can a tool do about it, and which choice actually tells you?

level: middleimportance: must knowfreq 55%

answer

  1. refuse, reduce, or keep both
  2. only one of the three is loud
  3. a returned table proves nothing
  4. inherited arithmetic in no diff
  5. count the pairs, state the reduction

basics

~10 s

Three kinds of disposition: refuse, because one value per cell is a stated precondition; resolve the cell with a default reduction; or keep both values in the cell. Only the refusal tells you.

solid answer

~50 s

A widening needs one value per cell, and designs disagree about what to do when they get two. A tool that treats uniqueness as a stated precondition checks the key-and-header pairs and **refuses**, producing no result. A tool whose widening surface accepts a **reduction** — the function applied when more than one value lands in the same cell — and supplies a default one applies it and hands back a clean-looking table. A tool whose cells can hold a collection keeps **both** values in that cell, which changes what the column holds. Only the first is loud. So never reason from 'it returned a table' to 'the pairs were unique'. The advice that holds under all three is the same: count distinct key-and-header pairs against row count before you widen, and if a reduction is genuinely wanted, state it rather than inheriting one.

go deeper

for a junior

Recall that a cell holds one value, so two rows aiming at the same cell force a decision. Remember that the tool may make that decision without saying so.

for a middle

Lay out all three dispositions and say which is observable. Then give the advice that holds regardless: count the distinct key-and-header pairs first, and write the reduction down if you want one.

for a senior

Show that you do not reason from a returned result to a clean input. Describe how you would make a permissive widening loud for a call whose correctness matters.

for a principal

The angle is portability of belief: a team that learned one disposition writes code that is only safe on that tool. A stated precondition check travels; a remembered outcome does not.

## Why there is a decision at all A **widening** turns one column's distinct values into new headers, filled from a second column. The result's cells are addressed by a row key — the identifying values — together with a header, and each address is one slot. If two input rows share an address, the shape cannot hold both numbers. Whatever happens next is a decision, and the interesting thing is that it is usually made by the tool rather than by you. ## The three dispositions | Disposition | What the caller sees | What it costs you | |---|---|---| | **Refuse** — uniqueness is a stated precondition, so the pairs are checked and no result is produced | An explicit failure at the widening | Nothing silent; you must resolve the grain before continuing | | **Reduce** — the surface accepts a reduction and supplies a default one, applied to the colliding values | A clean table, same shape you expected | The arithmetic is somebody else's choice and appears nowhere in your code | | **Keep both** — the cell holds a collection of the colliding values | A table whose cell holds more than one value | The column no longer holds plain measurements, and every later step meets that | The distinction that matters is not which is most convenient but **which of them is observable**. Only the refusal generates a signal. The second produces a table indistinguishable from the one you wanted; the third produces one that at least looks unusual at the next step, but nothing was raised at the widening. ## The reasoning error this invites The error is a silent inference: *the widening returned, therefore the input had one value per cell.* That inference is only sound under the first disposition, and you generally do not get to choose which disposition you are under — it is a property of the tool and sometimes of the surface you called within it. Worse, the belief travels. Somebody who learned the subject where widening refuses carries 'it would have errored' into a place where it never would, and somebody who learned it where a default reduction exists carries 'a widening averages duplicates' into a place where it refuses. The repair is not to memorise one tool's behaviour. It is to stop making the outcome claim at all and make the **precondition claim** instead, which is true everywhere. ## The two rules that hold under all three 1. **Count distinct key-and-header pairs against the input row count before you widen.** Equal means the widening is a rearrangement. Fewer distinct pairs than rows means at least one cell is being decided, and the difference is how many values are being absorbed. This check is arithmetic you own, not a feature you hope the tool has. 2. **If a reduction is genuinely what you want, state it.** A stated reduction is a visible line of code with a reviewable meaning: these two readings are averaged, or summed, or the later one wins. An inherited one is arithmetic that appears in no diff and in no review. Stating it also has a useful side effect where the surface allows it: naming a reduction that cannot silently absorb anything — one that fails or flags when handed more than one value — turns a permissive tool into a loud one for this call. ## What varies, and a cost claim not to make Two things genuinely differ across designs and should never be asserted flatly. - **Whether a default reduction exists, and what it is.** Some widening surfaces have none and refuse; others carry one. Where one exists you are inheriting a choice of arithmetic made by the tool's authors, and it is not the same choice everywhere. - **What it costs to supply your own reduction.** A common belief is that handing in your own function is inherently slow because it is called once per colliding value. That is one calling convention among several: some designs hand the reduction the whole set of colliding values at once under the same surface name, and some recognise a named reduction and dispatch it to a compiled path, so only an arbitrary supplied function ever takes the slow route. Establish which convention is in play before making a cost claim — and never let a cost belief talk you out of stating the reduction. ## The shape of a good answer in an interview Name the precondition, name the three dispositions, say which one is silent, and then give the advice that survives all three. A candidate who answers with a single outcome — 'it errors' or 'it averages them' — has described the tool they happen to know and has told the interviewer that they would not catch this anywhere else.

  • Why can you not simply rely on the reduction being harmless when the colliding values are identical?
    Because you are relying on a property of the data you have not checked, under arithmetic you did not choose. Identical values do make an average or a maximum a no-op, but nothing guarantees they stay identical next month, and a sum is not a no-op even today. The check is cheap and the assumption is unmonitored.
  • If a tool keeps both values in the single cell, what has actually changed about the result?
    The column no longer holds one measurement per cell, so it is not the same kind of column the rest of the pipeline expects. The disposition is at least visible at the next step rather than silent, but it is still not the table you asked for, and treating it as one is where the trouble starts.
  • How would you make a permissive widening behave like a strict one for a single important call?
    Run the pair count immediately before the call and stop on a mismatch, so the loudness comes from your code rather than the tool's. Where the surface lets you supply the reduction, naming one that refuses or flags a second value achieves the same thing at the point of use.

A sorting office with one pigeonhole per address. Two letters arrive for the same hole: one office refuses the delivery and tells you, one merges the contents into a single envelope, one leaves both letters in the hole. Only the refusal generates a notice — the merge looks exactly like a normal day's post.

saying these in an interview costs you the question

  • Says a widening errors on duplicates, as though every tool behaves that way
  • Says a widening averages duplicates, as though every tool behaves that way
  • Infers from a returned table that the key-and-header pairs were unique
  • Treats the reduction as a formatting detail rather than arithmetic on the data
  • Claims supplying your own reduction is always slower than a built-in one
  • Relies on a later reader noticing that a cell holds a collection