Recognising Coding Patterns
Choose a technique from the problem's rules rather than its name.
python, patterns, constraints, correctness, complexityLook for the shape of the problem
Imagine adding the pages read on three neighbouring days. The three-day groups overlap: when the window moves forward, most days are the same. That shared structure suggests reusing work rather than adding every group from scratch. A pattern is a reusable idea, not a shortcut around understanding the question.
First ask: are items ordered? Must chosen items be consecutive? Can values
repeat or be negative? What should an empty input return? A Python list has
numbered positions starting at zero; a slice such as days[1:4] includes
positions 1, 2 and 3, not 4.
Python illustration
days = [2, 4, 1, 3]
print(sum(days[0:3]))
print(sum(days[1:4]))
Prepared output:
7
8
The groups [2, 4, 1] and [4, 1, 3] are contiguous; only the first and
last values change. For two tiny groups, direct sums are clear. A fixed-size
sliding window can reuse the previous total for a longer list.
See the reasoning
Follow the example one step at a time
Compare overlapping groups before choosing a reusable technique. This is a prepared teaching demonstration, not live code execution.
First group
[2, 4, 1] 3 sum = 7
Three consecutive days form the first group.
From idea to reliable solution
State the input and output contract, trace an example, explain why the method cannot miss a valid answer, and check boundaries such as empty lists and duplicates. Compare time and extra memory for the actual implementation. For example, overlapping groups do not make every sliding-window problem linear: the update and any additional data structures matter. These are DSA techniques, not object-oriented design patterns.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
