Middle · Explain · Integrated problem solving

Which contracts must agree across parsing, aggregation, ranking and paging in the interview capstone?

Think through your answer before opening the explanation.

Coding interviews

Reveal answer and reasoning

Deliver a small complete interview solution with a written grammar, aggregation rule, deterministic ranking and bounded output page. Records contain one nonempty key, one colon and a nonnegative invariant integer quantity. Repeated ordinal keys add into checked long totals. Ranking is total descending then key ordinal ascending. This capstone uses an offset into a fixed snapshot, deliberately distinct from the earlier mutable-source keyset lesson.

Treat this as a deliverable with acceptance criteria rather than a puzzle whose only goal is one printout. The grammar, aggregation comparer, ordering and paging snapshot should all be written before coding. Keeping these contracts aligned is more important than compressing the pipeline into the fewest possible LINQ calls.

For n input code units and u distinct keys, parsing and hashing examine text, aggregation uses expected dictionary work and ranking adds O(u log u) comparisons with O(u) retained totals and ranked storage. A two-item page bounds only output, not all work or memory. Count text scanning, key hashing, retained totals and ranking separately. Skip one does not make the whole pipeline constant-time or constant-space because all records were parsed and all keys ranked first.

The page is deliberately tiny, while the result snapshot remains proportional to the number of distinct keys.

What a strong answer covers

  • Deliver a small complete interview solution with a written grammar, aggregation rule, deterministic ranking and bounded output page.
  • The first colon is located once and a second colon is rejected.
  • For n input code units and u distinct keys, parsing and hashing examine text, aggregation uses expected dictionary work and ranking adds O(u log u) comparisons with O(u) retained totals and ranked storage.

Common pitfall

Combining correct helpers can still produce a wrong system when their contracts disagree. The numeric grammar disallows signs and whitespace, whereas keys are preserved exactly. The fixed snapshot makes offset paging stable for this run; it does not make offsets safe across independent requests over changing data.

Follow-up questions

  1. Add malformed quantities, duplicate delimiters, tied totals and zero-valued rows. Hint: test failures separately from the successful fixture so one bad row does not obscure ordering checks. Verify that input remains unchanged.
  2. How would returning all parse errors change the publication and memory contract?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions