Loading
0x00Lesson 1 of 13

Solve problems out loud

Use a repeatable routine from clarifying questions to tested code.

20 min 5-question quiz 1 code exercise
By the end of this lesson you can
  • Follow a step-by-step routine for any coding problem.
  • Find edge cases before writing code.
  • Communicate your thinking while you work.

In a coding interview you solve an algorithm problem in 35-45 minutes, usually in a shared editor, while explaining your thinking. Interviewers grade more than the final code: they look at how you understand the problem, how you reason toward an efficient solution, how clean and correct your code is, and how you test it. A fixed routine keeps you calm and makes that reasoning visible.

A routine for every problem

  1. Clarify. Restate the problem. Ask about input size, value ranges, duplicates, empty input, and the expected output format.
  2. Work through examples. Solve one small example by hand, then list edge cases: empty, one element, all equal, negative numbers, very large input.
  3. Start with brute force. Say the simplest correct approach and its complexity, even if it is slow. It proves you understand the problem.
  4. Optimize. Look for repeated work. Which data structure or pattern removes it? State the new time and space complexity.
  5. Code. Write clean code with good names, narrating as you go.
  6. Test. Trace your code by hand on an example and on the edge cases, then fix bugs calmly.
solution.py
1def second_largest(nums):
2    distinct = sorted(set(nums))
3    if len(distinct) < 2:
4        return None  # edge case found while clarifying
5    return distinct[-2]
6
7print(second_largest([3, 1, 4, 1, 5]))
8print(second_largest([7, 7, 7]))
Output
4
None

Clarifying questions often change the problem. “Second largest” of [7, 7, 7] could mean 7 or “there isn’t one.” Asking turns a hidden trap into an explicit decision - and interviewers deliberately leave such gaps to see whether you notice them.

Key takeaways

  • Clarify, work examples, brute force, optimize, code, test.

  • Edge cases found early become part of the design, not bugs later.

  • Narrate your reasoning so the interviewer can follow and help.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: solve interview problems

Solve a classic interview problem in Python and run it against test cases. Aim for the optimal complexity, then check the edge cases. Exercises run locally in your browser.

Exercise 1

Handle the edge cases

+25 XP

Read a line of space-separated integers (it may be empty). Print the second largest distinct value, or none if there are fewer than two distinct values.

  • Typical input
  • All equal
  • Empty input
main.py
Loading editor…

Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Did you like the lesson? 😆👍
Consider a donation to support our work: