1414 Views

0 Likes

In this lesson, Alvin explores the strategy to solving the following interview problem:

Write a function,

array_stepper, that takes in a list of numbers as an argument. You start at the first position of the list. The function should return a boolean indicating whether or not it is possible to reach the last position of the list. When situated at some position of the list, you may take a maximum number of steps based on the number at that position.For example, given:

- idx = 0 1 2 3 4 5
- numbers = [2, 4, 2, 0, 0, 1]
The answer is True.

We start at idx 0, we could take 1 step or 2 steps forward.

The correct choice is to take 1 step to idx 1.

Then take 4 steps forward to the end at idx 5.

```
array_stepper([2, 4, 2, 0, 0, 1]) # -> True
```

```
array_stepper([2, 3, 2, 0, 0, 1]) # -> False
```

```
array_stepper([3, 1, 3, 1, 0, 1]) # -> True
```

```
array_stepper([4, 1, 5, 1, 1, 1, 0, 4]) # -> True
```

```
array_stepper([4, 1, 2, 1, 1, 1, 0, 4]) # -> False
```

If you need additional support taking these DSA skills and actually applying them, take **Alvin's** *complete* data structures and algorithms course on **Structy**. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use **this link to get 20% off** the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: **https://www.linkedin.com/in/alvin-zablan-b73a92117/**

Related Videos

0:48

DSA Crash Course [Part 87] - Outro

5:27

DSA Crash Course [Part 86] - Array Stepper Walkthrough

6:31

DSA Crash Course [Part 84] - Counting Change Walkthrough

6:26

DSA Crash Course [Part 83] - Counting Change Approach

5:52

DSA Crash Course [Part 82] - Summing Squares Walkthrough

6:22

DSA Crash Course [Part 81] - Summing Squares Approach

8:00

DSA Crash Course [Part 80] - Non Adjacent Sum Walkthrough

8:33

DSA Crash Course [Part 79] - Non Adjacent Sum Approach

5:34

DSA Crash Course [Part 78] - Max Path Sum Walkthrough

6:15

DSA Crash Course [Part 77] - Max Path Sum Approach

Explore TrendingLayoffsPerformance Improvement PlanSystem DesignInterpersonal CommunicationTech Lead