PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency with array/list manipulation, parity checking, and handling edge cases such as negative values and integers outside 32-bit ranges.

  • easy
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Print all odd numbers from an integer list

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Given a list/array of integers `nums`, **print (or return) every odd number** in the list, in the **same order** they appear. ### Clarifications / follow-ups 1. **Negative integers may appear.** Negative odd numbers (e.g., `-3`) should be treated as odd and included. 2. **Integers may exceed 32-bit range.** Your approach should still work even if values do not fit in a 32-bit signed integer. ### Input - `nums`: a list of integers. ### Output - Either print each odd number (one per line) or return a list of odd numbers (state your choice). ### Constraints - Assume `nums` can be large, so the solution should be linear in the length of the list.

Quick Answer: This question evaluates proficiency with array/list manipulation, parity checking, and handling edge cases such as negative values and integers outside 32-bit ranges.

Given a list/array of integers `nums`, return every odd number in the list, in the same order they appear. Notes / follow-ups: 1. Negative integers may appear. Negative odd numbers (e.g. -3) are still odd and should be included. 2. Integers may exceed the 32-bit signed range. Your approach must still classify them correctly (use a 64-bit / big-integer type where the language requires it). Return a new list containing the odd numbers in their original relative order. The solution should be linear in the length of the input.

Constraints

  • 0 <= len(nums)
  • Integers may be negative.
  • Integers may exceed the 32-bit signed range; classification must remain correct.
  • Solution must run in linear time over the length of nums.

Examples

Input: ([1, 2, 3, 4, 5],)

Expected Output: [1, 3, 5]

Explanation: Odd numbers 1, 3, 5 kept in their original order; evens 2 and 4 dropped.

Input: ([2, 4, 6, 8],)

Expected Output: []

Explanation: No odd numbers, so the result is empty.

Input: ([],)

Expected Output: []

Explanation: Empty input yields an empty result.

Input: ([-3, -2, -1, 0, 1],)

Expected Output: [-3, -1, 1]

Explanation: Negative odds -3 and -1 are included; 0 and -2 are even.

Input: ([7],)

Expected Output: [7]

Explanation: Single odd element is returned as-is.

Input: ([10000000000000000001, 10000000000000000002],)

Expected Output: [10000000000000000001]

Explanation: Value far beyond 32-bit range: the odd one is kept, demonstrating parity works for large integers.

Input: ([0, -0, 5, -5],)

Expected Output: [5, -5]

Explanation: 0 and -0 are even; the odd values 5 and -5 are kept in order.

Hints

  1. An integer x is odd exactly when x % 2 != 0. Avoid `x % 2 == 1`, which is false for negative odds in languages where `%` keeps the sign of the dividend.
  2. Iterate once and collect matching elements; do not sort or use nested loops.
  3. For languages with fixed-width ints (Java, C++), use a 64-bit type so values beyond the 32-bit range are still tested correctly. Parity (even/odd) does not depend on width, so the same `% 2` check works.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)