P-7.3 The Patterns Most Questions Use

Standard screening-question shapes — written September 2026

What this is and why it exists

Screening questions are drawn from a small set of shapes. Recognising the shape is most of the work.

Four of them cover a large share of what a first round asks. They are worth knowing by the names people actually use: two pointers, a sliding window, counting with a hash table, and running totals.

This is recognition practice, not new theory. The structures themselves were taught in the data structures module and are not repeated here. What is added is the habit of naming the shape first and writing second.

The vocabulary

  • Two pointers — two indexes that each move once, rather than nested loops.
  • Sliding window — a range whose edges move, instead of being rebuilt.
  • Counting — using a hash table to record how many times each thing appeared.
  • Running total — a precomputed total from the start, so ranges cost one subtraction.
  • Shape — the underlying form a question takes, whatever its story.

The mental model

Two pointers. A sorted-array question that looks like it needs two nested loops usually needs two indexes that each move once. One from each end, or one chasing the other. The shape turns quadratic work into a single pass. Recognising it is the entire trick, and there is not much else to learn.

A sliding window. Questions about the best run of consecutive items are window questions. Instead of rebuilding the range at every position, you add the item that enters and remove the item that leaves. That is what keeps the cost linear rather than quadratic, and the give-away phrase is usually "consecutive" or "contiguous".

Counting with a hash table. Anything phrased as *most frequent*, *first repeated*, or *seen before* is a counting question. The table buys average constant-time lookup. It spends memory, and saying that trade out loud is part of a good answer rather than an admission.

Running totals. Precompute the total from the start of the array, and any range can then be answered with one subtraction. It is the cheapest example of a general idea worth carrying: pay once, so that many later questions cost nothing.

Then do the exercise, which is deliberately not about writing code. Take ten unseen questions and name the shape of each one, without solving any of them. Naming the shape first is the habit that makes a round feel shorter than its clock, and it is trainable in a single afternoon.

What you should now be able to explain or do

Recognise a two-pointer question and say what it replaces. Recognise a window question from its phrasing and say what moving the edges saves. Recognise a counting question and name its memory cost out loud. Use a running total to make range sums free. Take ten unseen questions and name each shape before writing anything.

Check yourself

Nested loops over a sorted array. Two indexes that each move once turn quadratic work into a single pass.

It asks about the best run of consecutive or contiguous items. The saving comes from moving the edges instead of rebuilding the range.

Most frequent, first repeated, or seen before. A hash table answers all three, and its memory cost is worth stating.

Paying once so that many later questions cost nothing. One precomputation makes every range sum a single subtraction.

Because recognition is the slow part under a clock, and it is trainable on its own in an afternoon.

Go deeper

Back to The Patterns Most Questions Use: work through the checklist