Hello @Sriram_Balasubramani,
Let’s go over this problem in steps to answer you query. Please note that it’s given in the statement that the route is circular, so we don’t need to explicitly check that.
- At the start of the function, we check if it is possible to complete the journey based on total gas and cost.
- If this check returns true, we know for sure that the journey is possible on this circular route.
- After that, all we need to do is to find the starting index of the journey, where the difference between the gas and the cost is positive. If, at any point, the gas in our tank drops below zero, we cannot reach the next station nor finish the circular route.
Hope this clears your confusion. Feel free to share more suggestions and queries. Thanks.