Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python solution of Advancing Through an Array fails EPIJudge tests #224

Open
drogers141 opened this issue Jan 21, 2022 · 1 comment
Open

Comments

@drogers141
Copy link

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_index

I 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.

@drogers141
Copy link
Author

I just noticed that the test that failed is the array that was used as an example in the book as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant