Arrays in Python: Array Advance Game

preview_player
Показать описание
In this video, we will be considering the so-called "array advance game". In this game, you are given an array of non-negative integers. For example:

[3,3,1,0,2,0,1].

Each number represents the maximum you can advance in the array.

Question:
Is it possible to advance from the start of the array to the last element?

We will cover how to solve this problem algorithmically, and then code up a solution to this question in Python.

The software written in this video is available at:

Slides for this video are here:

Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:

If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
Рекомендации по теме
Комментарии
Автор

Really helpful and clear. Thanks sir. As a beginner I'm very lucky to find your videos.

huidongxu
Автор

I want to thank you for this video and all the Python Data Structure videos. Your channel is my to go for learning all about solving the dreaded technical problems.

msugal
Автор

hey man . i really like your videos and would love to see more of these coding interview type problems in python

ravitanwar
Автор

This is so elegant! would be great if you could also do problems like finding maximum subsequence and substring between two arrays/strings.

axygh
Автор

thank you sir.i am a beginner.your videos are very helpful.thanks

jowadulkader
Автор

Please Help me, why this code always gives me result as true even for impossible situations!
arr = [3, 2, 0, 0, 2, 0, 1]
furthest_reached = 0
count = 0
for i in range(len(arr)-1):
furthest_reached = max(furthest_reached, arr[i]+i)
if i>furthest_reached:
break
else:
count+=1
if count >= len(arr)-1:
print("The Winning is possible")
else:
print("Not Possible!")

stonecoldcold
Автор

So I paused the video before you showed the approach that you ended up writing in python and tried to solve it myself. I came up with an approach that would find the max of all the values that are possible to move to from the current position, and move to that position.
So for example, if the array given was [3, 3, 1, 0, 2, 0, 1], I'd start at position 0 (3) and find the max of positions 1-3 ([3, 1, 0]); I'd change the current position to the index of the max value found and continue on until I either hit the end of the array or reached a 0 beforehand. I also made sure to find the 'leftmost' max for situations where multiple positions were of equal highest value.
What are your opinions on my approach? Do you think there are arrays for which my approach wouldn't work (I feel like there might be lol).

YaBoiGuzma
Автор

Why is why not furthest_reached==last_idx

pavassrivastava