Learn
Exam

String Slicing

Difficulty
STARTER

Problem

Given a string word, a starting index start, and an ending index end, write a function solution that returns the substring of word from start to end, inclusive.


Constraints

  • word consists only of lowercase English letters.
  • The length of word is between 1 and 100 inclusive.
  • start and end are natural numbers such that 0 <= start <= end <= (length of word - 1).
  • start is always less than or equal to end.

Test Case

Test Case Number word start end return
1 "hello" 1 3 "ell"
2 "algorithm" 0 4 "algor"
3 "substring" 2 5 "bstr"

Explanation for Test Case 1

  • When word = "hello", start = 1, and end = 3, slicing from index 1 to 3 yields "ell".

Explanation for Test Case 2

  • When word = "algorithm", start = 0, and end = 4, slicing from index 0 to 4 yields "algor".

Explanation for Test Case 3

  • When word = "substring", start = 2, and end = 5, slicing from index 2 to 5 yields "bstr".