Step 01 Beginner Problems — Fundamentals of Programming
How to Think Like a Programmer
Staring at a problem and feeling blank is not a talent problem — it is a process problem. Programmers who look 'naturally good' are running a quiet checklist in their heads: understand, break down, start with a dumb solution, look for the pattern, then refine. This lesson makes that checklist explicit so you can run it deliberately on every problem in this sheet.
Step 1–2: Understand, then decompose
First, restate the problem in your own words and pin down the exact input and output with one concrete example. Most 'I don't know where to start' moments are actually 'I haven't understood what is being asked' moments.
Then decompose: split the goal into sub-tasks you already know. 'Check if a number is a palindrome' becomes: reverse the number (a loop you know), then compare two values (trivial). Almost every hard problem is a chain of easy sub-problems wearing a costume; your job is to find the seams.
Step 3: Solve it by hand first
Before writing any code, do two or three examples on paper with actual numbers. Write the intermediate values down. The mechanical steps you find yourself repeating are your loop; the values you keep track of are your variables; the condition you check before stopping is your loop condition. Code is just this paper process transcribed — if you cannot do it by hand, you cannot yet code it.
Step 4–5: Brute force first, then hunt the pattern
Write the obvious, slow solution first. A correct brute force proves you understood the problem, gives you a reference to test faster versions against, and in interviews earns most of the marks by itself.
Only then optimise, and optimise by pattern: Does the problem mention pairs or a sorted array? Two pointers. Subarrays with a condition? Sliding window or prefix sums. 'How many times does X occur?' Hashing. Choices that branch? Recursion. With practice these triggers become automatic — that automaticity is what people call 'talent'.
Step 6: Attack your own solution
Before declaring victory, try to break it. Feed it 0, 1, negative numbers, a single element, all duplicates, and the maximum size the constraints allow. Programmers think like adversaries of their own code. The Dry Runs and Debugging lesson turns this into a concrete routine.
Key points
- Blank-page panic is a process problem: run the checklist instead of waiting for inspiration.
- Restate the problem, fix input/output with a concrete example, then decompose into known sub-tasks.
- Solve examples by hand first — the repeated steps become your loops and variables.
- Always build a correct brute force before optimising; it anchors testing and interviews.
- Optimisation is pattern matching: pairs→two pointers, subarrays→sliding window, counting→hashing, branching→recursion.
- Finish by attacking your own solution with hostile inputs.