← Questions

Print the odd numbers in a list

0
AmazonCodingLast asked Jan 2026

A coding interview question asked in Amazon's technical phone screen, last asked Jan 2026. It tests arrays and basics.

Given a list of integers, print every odd number in it, one per line, in the order they appear.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • print_odds(nums: list[int]) -> None — prints each odd value of nums on its own line; prints nothing for an empty list.

Example

print_odds([4, 7, -3, 0, 10, 15])
7
-3
15

Constraints

  • The list may be empty.
  • Values may be negative, and may not fit in 32 bits.

Clarifying questions

  • Should a repeated value be printed every time it appears?
  • Print, or return a new list?
  • Can the input contain values that are not integers?

What a strong answer covers

  • A parity check that is right for negative numbers: in Python -3 % 2 == 1, but in Java or C++ -3 % 2 == -1, so x % 2 == 1 misses negative odd numbers there; x % 2 != 0 or x & 1 works in all of them.
  • Overflow: in a fixed-width language, very large values need a 64-bit or arbitrary-precision type.
  • One pass, O(n) time and O(1) extra space.
  • Tests: empty list, all even, negative odd values, zero, very large values.

Follow-ups

  • Return the odd numbers instead of printing them, lazily, as a generator.
  • The list is too large for memory and arrives as a stream.

Where it's asked

  • Amazon · Technical phone screen · Last asked Jan 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI

What it tests

arrays · basics

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding