Reproduce it with the smallest input that gives a wrong result, and work out by hand what the right answer should be. Then narrow down where the actual behaviour diverges from what you expect, using a debugger with breakpoints or a few targeted print statements to check values at key points. Test one hypothesis at a time, fix the root cause, and keep the failing case as a test so the bug cannot return.
Why interviewers ask this
Debugging is a big part of any internship, and interviewers want to see a systematic approach rather than random changes until something works. They listen for reproducing the problem, shrinking it to a small case, checking assumptions step by step and using a debugger. Writing a test for the bug afterwards, and explaining why it happened, shows the kind of habits teams value in juniors.
How to structure your answer
- Reproduce the bug with the smallest failing input.
- Work out the expected result and where it diverges.
- Use a debugger or targeted prints, one hypothesis at a time.
- Fix the root cause and keep the case as a test.
Example answer
The first thing I do is reproduce it with the smallest input I can, because a bug is far easier to see in a ten line example. I work out by hand what the right answer should be, so I know exactly what I am aiming for. Then I narrow down where things go wrong. I set breakpoints in the debugger and step through, checking that each variable holds what I think it should. When I cannot use a debugger, I add a few print statements at key points rather than everywhere. The idea is to find the first place where reality differs from my expectation. On one coursework assignment, my program calculating average grades was slightly off for some students. Stepping through showed that integer division was rounding each module score down before the average was taken. One change fixed it, but the useful part was understanding why. Then I add the failing input as a test case, so if anyone breaks it again the test catches it. If I am still stuck, explaining the code line by line to someone often shows me the mistake.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What would you do if the bug only happened some of the time?
- How do you use breakpoints and watch expressions in a debugger?
- When would you ask someone else for help with a bug?
Related software engineering intern questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions