Problem Description
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 i-th round starts at sector rounds[i - 1] and ends at sector rounds[i]. The task is to return an array of the most visited sectors sorted in ascending order.
Key Insights
- The track is circular, so after reaching the last sector, the next sector is the first one.
- We need to count the number of visits to each sector during the rounds.
- Sectors can be visited multiple times within a round, especially if the start sector is greater than the end sector.
Space and Time Complexity
Time Complexity: O(m + n)
Space Complexity: O(n)
Solution
To solve this problem, we can use an array to count the visits to each sector. We will iterate through the rounds to determine the sectors visited in each round. For each round, we will handle the circular nature of the track by incrementing the sector index and wrapping around when necessary. Finally, we will find the maximum visit count and return all sectors that have that count.