Skip to main content
Back to problems
#1560
Easy Algorithms

Most visited sector in a circular track

Array Simulation
59.8% acceptance
Feb 25, 2026
338
672
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]. Return an array of the most visited sectors sorted in ascending order. Notice that you can repeat sectors in the rounds in this marathon.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn most_visited(n: i32, rounds: Vec<i32>) -> Vec<i32> {
    let start = rounds[0];
    let end = *rounds.last().unwrap();
    if start <= end {
      (start..=end).collect()
    } else {
      let mut res: Vec<i32> = (1..=end).collect();
      res.extend(start..=n);
      res
    }
  }
}