educative.io

The code vs the algorithms description

Its a bit unclear. In the code we iterate once through every gas station and the costs, and memorise the first element there we could start the journey. In the description though, there is one more for loop to actually verify the start point and the values would actually match to have a round trip. Does that mean we actually not needed this verification? Thanks,


Course: Grokking Coding Interview Patterns in Go - Learn Interactively
Lesson: Solution: Gas Stations

1 Like

Hi @Arkady,

Yes, you are on the right track. We don’t actually need another loop to verify that we can make a round trip back to the starting point. That step is just to help you explain how the index we find during our journey actually returns to the starting position. You don’t need to implement this part in the code, as it isn’t discussed in the problem statement.

Please feel free to share further feedback and suggestions. We’d be happy to help. Thanks!

Happy learning!