Learn
Exam

Array Slicing

Difficulty
STARTER

Problem

Given an array numbers consisting of natural numbers and two integers start and end, write a function solution that returns a new array containing elements from numbers starting at index start and ending at index end.


Constraints

  • Each element in numbers is a natural number not exceeding 20.
  • numbers is not empty, and its length does not exceed 100.
  • start and end are integers between 0 and the length of numbers, inclusive.
  • start is always less than or equal to end.

Test Case

Test Case Number numbers start end return
1 [1] 0 0 [1]
2 [1, 2, 3, 4, 5] 1 3 [2, 3, 4]
3 [4, 5, 6] 0 2 [4, 5, 6]

Explanation for Test Case 1

  • Given numbers = [1], start = 0, and end = 0, selecting only the 0th index results in [1].

Explanation for Test Case 2

  • Given numbers = [1, 2, 3, 4, 5], start = 1, and end = 3, selecting from the 1st to 3rd index results in [2, 3, 4].

Explanation for Test Case 3

  • Given numbers = [4, 5, 6], start = 0, and end = 2, selecting from the 0th to 2nd index results in [4, 5, 6].