Back to classes

Practice problems / Algorithms

Algorithms

0/11 solved

Generate Odd Numbers

Easy

Return an array containing all odd numbers from 1 to n (inclusive). Return empty array if n < 1.

Constraints

  • n is an integer
  • n can be negative, zero, or positive
  • Return new array, do not modify inputs

Examples

InputExpected Output
printOddNumbers(10)[1, 3, 5, 7, 9]
printOddNumbers(5)[1, 3, 5]
printOddNumbers(0)[]

Write your solution and click “Run tests” to see results here.