Solve problems out loud
Use a repeatable routine from clarifying questions to tested code.
- 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
- Clarify. Restate the problem. Ask about input size, value ranges, duplicates, empty input, and the expected output format.
- Work through examples. Solve one small example by hand, then list edge cases: empty, one element, all equal, negative numbers, very large input.
- Start with brute force. Say the simplest correct approach and its complexity, even if it is slow. It proves you understand the problem.
- Optimize. Look for repeated work. Which data structure or pattern removes it? State the new time and space complexity.
- Code. Write clean code with good names, narrating as you go.
- Test. Trace your code by hand on an example and on the edge cases, then fix bugs calmly.
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]))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.
Handle the edge cases
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
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…