File: most-visited-sector-in-a-circular-track/solution.py

Date: 2026-06-06

Time: 18:08

most-visited-sector-in-a-circular-track/solution.py

This solves LeetCode 1560. The problem describes a marathon on a circular track with n sectors (labeled 1 to n). A runner completes several rounds described by the rounds array, and you must return which sectors were visited the most, in ascending order.

Key Insight

The solution skips simulating the race entirely. It only looks at rounds[0] (start) and rounds[-1] (end). This works because every sector traversed during intermediate rounds is visited the same number of times — complete traversals between waypoints contribute uniformly. The only asymmetry is the partial arc from the starting sector to the ending sector, which gets one extra visit compared to sectors outside that arc.

mostvisitedsector(n, rounds) -> List[int]

Two cases based on the relative position of start and end on the circular track:

The output is always in ascending order because range(1, end+1) precedes range(start, n+1) numerically.

Complexity

Dependencies

Only imports List from typing for the type annotation. No internal dependencies. The test file at most-visited-sector-in-a-circular-track/test_solution.py imports this function.

Invariants

Error Handling

None. The function trusts its inputs match the problem's constraints (1 <= rounds[i] <= n, len(rounds) >= 2). No validation or exception handling.

Topics to Explore

Beliefs