Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Gas StationStep-by-Step Visualization

Determine if a circuit traversal is possible. This requires identifying the correct starting point.

Problem Statement

There are n gas stations along a circular route. Given gas and cost arrays, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

Approach

If total gas < total cost, impossible. Otherwise, a solution exists. Iterate through. Track `currentTank`. If `currentTank` drops below 0, reset start point to i+1 and `currentTank` to 0. The valid start point survives.

Time & Space Complexity

Time complexity is O(n). Space complexity is O(1).

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.