TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation Β· 5.9K subscribers
Post #1350 432
πŸ› SPOT THE BUG #1
Language: Python

python
def get_average(scores):
total = 0
for score in scores:
total += score
return total / len(scores)

print(get_average([]))


What breaks here? Try to spot it before reading on πŸ‘‡

.
.
.

The bug: ZeroDivisionError when scores is empty. It's an easy edge case to forget under interview pressure, but interviewers plant empty-input tests specifically to see if you check for them.

Fixed version:
python
def get_average(scores):
if not scores:
return 0 # or raise a meaningful exception, depending on requirements
return sum(scores) / len(scores)


πŸ’‘ Takeaway: Before you write a single line of code in an interview, say out loud: "What happens with an empty input? A single element? Negative numbers?" It shows structured thinking, and it catches bugs like this before they exist.
More from @coding_interview_preparation
  1. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  2. Oct 6, 2026document post
  3. Oct 4, 2026πŸ’Ό Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  4. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  5. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
  6. Sep 30, 2026πŸ’Ό What Companies Actually Look For in a Fresher Think companies only care about your CGPA…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’