-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
The solution for Advancing Through an Array (5.4 page 44) as written fails the first test.
I copied the solution from the text as:
def can_reach_end(A: List[int]) -> bool:
furthest_reach_so_far, last_index = 0, len(A) - 1
i = 0
while i <= furthest_reach_so_far and furthest_reach_so_far < last_index:
furthest_reach_so_far = max(furthest_reach_so_far, A[i] + 1)
i += 1
return furthest_reach_so_far >= last_indexI ran the test using advance_by_offsets.py in epi_judge_python
This results in the test output:
Test FAILED ( 1/2004)
Arguments
A: [3, 3, 1, 0, 2, 0, 1]
Failure info
explanation: A valid advance sequence is: 0->1->4->6->6
expected: True
result: False
I have a solution that passes all the tests, which I'm happy to share if that is useful. Your solution does a single pass over the array. This seems awesome, however I don't see how it can work in all cases.
Metadata
Metadata
Assignees
Labels
No labels