O58

Gas Station Circular Tour

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

Problem Statement & Objective

There are n gas stations along a circular route. Return the starting gas station's index if you can travel around the circuit once, otherwise return -1.

Function Signature (Python)

gas_station_circular_tour(gas: list[int], cost: list[int]) -> int

Input & Output Contract

Output Rule:Başlangıç istasyonu indeksi (0-tabanlı) veya -1.

System Constraints

n == benzin.length == maliyet.length
1 <= n <= 10^5
0 <= benzin[i], maliyet[i] <= 10^4

Example Execution Walkthrough

benzin = [1, 2, 3, 4, 5], maliyet = [3, 4, 5, 1, 2]
3. istasyondan başlanırsa tur tamamlanabilir -> cevap: 3

Example Test Scenarios (3)

Example 1
Input:[[1,2,3,4,5],[3,4,5,1,2]]
Expected Output:3
Example 2: Yetersiz Toplam
Input:[[2,3,4],[3,4,3]]
Expected Output:-1
Example 3: Tek İstasyon
Input:[[5],[4]]
Expected Output:0
Loading Python Editor...
Input Parameters
[
  [
    1,
    2,
    3,
    4,
    5
  ],
  [
    3,
    4,
    5,
    1,
    2
  ]
]
Expected Output
3