EasyPythonJavaScriptTypeScript

Range Array

ArraysFunctions

Implement solve(start, end, step) that generates an array of numbers from
start (inclusive) up to end (exclusive) with the given step.

Examples

  • solve(0, 5, 1)[0,1,2,3,4]
  • solve(0, 10, 2)[0,2,4,6,8]
  • solve(5, 0, -1)[5,4,3,2,1]

Constraints

  • step !== 0
  • Return an empty array if the range would produce no values.

Sample tests

Test #1Basic forward range
Input: [0,5,1]
Output: [0,1,2,3,4]
Test #2Forward range with step 2
Input: [0,10,2]
Output: [0,2,4,6,8]
Test #3Backwards range
Input: [5,0,-1]
Output: [5,4,3,2,1]
Test #4start === end → empty array
Input: [3,3,1]
Output: []
Test #5Fractional step
Input: [0,1,0.5]
Output: [0,0.5]