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
wordconsists only of lowercase English letters.- The length of
wordis between 1 and 100 inclusive. startandendare natural numbers such that0 <= start <= end <= (length of word - 1).startis always less than or equal toend.
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, andend = 3, slicing from index 1 to 3 yields"ell".
Explanation for Test Case 2
- When
word = "algorithm",start = 0, andend = 4, slicing from index 0 to 4 yields"algor".
Explanation for Test Case 3
- When
word = "substring",start = 2, andend = 5, slicing from index 2 to 5 yields"bstr".