Well this one was embarrassing, I flubbed a lot of the base cases. I spent the most amount of time, however, trying really hard to see what I was missing: frankly, I don’t see why this is considered a harder question (“Medium”), and I don’t really see why this would be considered dynamic programming or be part of the study plan.
So yes, there is sort of a recurrence we’d want, as demonstrated in the solution…
class Solution:
def canJump(self, nums: List[int]) -> bool:
# We can (implicitly) make a DAG and now we're just finding
# some kind of reachability/length
# This seems a bit too easy... isn't reachability here really simple?
# We can do normal reachability, but isn't this sort of an integer?
# We keep the max of our current run, and what we currently see.
v = nums[0]
for w in nums[1:]:
if v <= 0:
return False
v -= 1
v = max(v, w)
return True
You can see my comments revealing my confusion. There’s no real “there”, there, in my opinion. I’m gathering this and all its friends from the study plan in this tag.