Skip to content

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

@drogers141

Description

@drogers141

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions