Problem Solving Using Programming MCQs for NSCT
Problem solving using programming means turning a worded problem into short, correct code and predicting exactly what a given piece of code will do. It is one of the 16 topics in the Problem Solving & Analytical Skills area, which carries 20% of the NSCT according to HEC's Areas of Competencies. In 2026 this area averaged 49.1% accuracy, and application-tier questions averaged 45.1%, per the HEC NSCT report.
From problem to code
Most short programs are built from a few standard patterns. Spotting which one a task needs is half the work.
| Pattern | What it does | Typical setup |
|---|---|---|
| Accumulator | Builds a running total or product | total = 0 before the loop, total += x inside |
| Counter | Counts items that meet a condition | count += 1 inside an if |
| Flag | Records whether something happened | found = False, set to True in the loop |
| Running maximum | Tracks the best value so far | best = a[0], then compare each item |
| Digit loop | Processes a number digit by digit | n % 10 for the last digit, n //= 10 to drop it |
Stepwise refinement turns a large task into these pieces: state the task in one line, split it into steps, and refine each step until it is a few lines of code. Exam angle: "Which code solves the task?" items usually differ in one detail, such as > against >= or a count against a sum, so check each option on a small input.
Code tracing
Code tracing (a dry run) means executing code by hand and recording each variable's value in a trace table.
a, b = 0, 1
for _ in range(4):
a, b = b, a + b
print(a)
| Pass | a | b |
|---|---|---|
| start | 0 | 1 |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 3 |
| 4 | 3 | 5 |
It prints 3. In the tuple assignment both right-hand values are computed before either variable changes. Exam angle: writing a = b and b = a + b on separate lines gives a different result, and examiners like that contrast.
Output prediction
Output prediction questions test exact language behaviour. The same expression can give different results in different languages:
| Expression | Python 3 | C, C++, Java (int) |
|---|---|---|
7 / 2 |
3.5 | 3 |
-7 // 2 (Python), -7 / 2 (C, Java) |
-4 (floors) | -3 (truncates) |
-7 % 2 |
1 | -1 |
2 ** 3 ** 2 |
512 (right-associative) | no ** operator |
Other favourites are slicing (s[::-1] reverses), list aliasing (y = x shares one list), recursion order (a print after the recursive call runs on the way back), and JavaScript's default sort(), which compares numbers as strings. Exam angle: read the exact print format too: end=" ", commas and brackets all change which option matches.
Common traps
- Assuming
range(1, n)includes n. - Confusing a function that prints with one that returns; the second gives None when printed.
- Forgetting that
x = x + [4]makes a new list butx += [4]changes the shared one. - Mixing up
//and/, or Python's floor division with C's truncation. - Missing that
andandorshort-circuit, so the right-hand side may never run. - Using two separate
ifstatements whereelifwas intended.
Worked examples
1. Understanding. A task asks how many students scored above 80. Which pattern fits best?
Answer: a counter. Set count = 0 before the loop and add 1 inside if mark > 80. An accumulator would add the marks themselves, which answers a different question.
2. Application. What does this print?
x = 1
for i in range(1, 5):
x = x * i if i % 2 else x + i
print(x)
Answer: 13. Odd i multiplies and even i adds: i = 1 gives 1 × 1 = 1, i = 2 gives 1 + 2 = 3, i = 3 gives 3 × 3 = 9, and i = 4 gives 9 + 4 = 13.
3. Analysis. This code should return the largest of three numbers. What does big3(7, 2, 3) return, and why?
def big3(a, b, c):
if a > b and a > c:
big = a
if b > a and b > c:
big = b
else:
big = c
return big
Answer: 3, which is wrong. The first if sets big = 7, but the second if is a separate statement. Its test is false, so its else runs and overwrites big with c. Changing the second if to elif makes the three branches exclusive and returns 7.
Practise Problem Solving Using Programming MCQs
The quiz below has 98 questions that you can filter by tier and difficulty.
Practise: 98 questions
FAQs
How do I get faster at output prediction?
Trace on paper with a table instead of in your head, and practise on short snippets daily. Learn the handful of language rules that examiners reuse: range bounds, floor division, slicing, mutable lists, default arguments and recursion order. Once those are automatic, most questions become two or three minutes of careful tracing.
Which language should I practise in?
Our questions mainly use Python, with some JavaScript, because both read like pseudocode. The skills of tracing, choosing loops and spotting boundary errors carry over to C++ and Java. Learn the few rules that differ, especially integer division and the modulo of negative numbers, so a change of language does not catch you out.
How is this topic different from the Programming area?
This topic tests problem solving through code: tracing logic, predicting output and picking the right pattern for a task. Programming is a separate area in HEC's list, with its own topics on language concepts. The two overlap, so practising both helps; see the Programming MCQs.
What should I do when a trace gets long?
Trace the first two or three passes fully, then look for the pattern, such as a value doubling or a sum of the first n numbers. Use that pattern to jump to the final pass, then check the last step by hand. This avoids arithmetic slips across ten or more passes.
Next step
Continue with Data-Driven Problem Solving, the next topic in HEC's order. You can also review Complexity & Efficiency Awareness, browse all Problem Solving MCQs, or try an NSCT mock test.