data_structures.arrays.gas_station ================================== .. py:module:: data_structures.arrays.gas_station Classes ------- .. autoapisummary:: data_structures.arrays.gas_station.GasStation Functions --------- .. autoapisummary:: data_structures.arrays.gas_station.can_complete_circuit Module Contents --------------- .. py:class:: GasStation Bases: :py:obj:`NamedTuple` .. py:attribute:: cost :type: int .. py:attribute:: gas :type: int .. py:function:: can_complete_circuit(gas_stations: list[GasStation]) -> int Finds the starting station index to complete the circuit, or returns -1 if not possible. Args: gas_stations (List[GasStation]): List of gas stations with gas and cost. Returns: The index of the starting station, or -1 if no solution exists. Examples: >>> GS = GasStation >>> test_stations = ( ... [GS(1, 3), GS(2, 4), GS(3, 5), GS(4, 1), GS(5, 2)], ... [GS(2, 3), GS(3, 4), GS(4, 3)], ... [GS(5, 4), GS(1, 4), GS(2, 1), GS(3, 5), GS(4, 1)] ... ) >>> can_complete_circuit(test_stations[0]) 3 >>> can_complete_circuit(test_stations[1]) -1 >>> can_complete_circuit(test_stations[2]) 4