Ctrl K

The Busiest Sectors of the Track

Easy
A circular track is split into sectors sectors numbered 1 to sectors. The runner always moves in increasing order of numbers, and after sector sectors comes sector 1 again. The run consists of legs: leg i starts at sector checkpoints[i] and ends at sector checkpoints[i + 1]. The runner starts at checkpoints[0], which also counts as visited; the end of one leg is the start of the next and is not counted twice. Return the sectors the runner visited the most times, in ascending order.
Example 1
sectors=5, checkpoints=[2, 4, 1] → [1, 2, 3, 4, 5]

The route is 2 → 3 → 4 → 5 → 1. Every sector is visited once, so all of them are the answer.

Example 2
sectors=3, checkpoints=[3, 2, 1] → [1, 3]

The route is 3 → 1 → 2 (end of a leg) → 3 → 1. Sectors 1 and 3 are visited twice, sector 2 once.

Constraints
  • 2 ≤ sectors ≤ 100
  • 2 ≤ len(checkpoints) ≤ 101
  • 1 ≤ checkpoints[i] ≤ sectors
  • checkpoints[i] ≠ checkpoints[i + 1]
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Long the Light Stayed On EasyRepack the Tray EasyQuiz Score Log EasyMirror and Negate a Bitmap EasySwap Rows and Columns Easy
loading Python…
Input
sectors=5, checkpoints=[2, 4, 1]
Expected
[1, 2, 3, 4, 5]

Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.