#1560
Most Visited Sector in a Circular Track
pupil · 440 · lc easy +26 · verified · 59.8% accepted · 338 likes · top 58%
Description
A circular track has n sectors labeled 1 to n. A marathon runs multiple rounds; the ith round goes from sector rounds[i-1] to sector rounds[i] in the direction of increasing sector numbers (wrapping around). Return a sorted list of the most-visited sectors.
Example 1:
Input: n = 4, rounds = [1,3,1,2]
Output: [1,2]
Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:
1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)
We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.
Example 2:
Input: n = 2, rounds = [2,1,2,1,2,1,2,1,2]
Output: [2]
Example 3:
Input: n = 7, rounds = [1,3,5,7]
Output: [1,2,3,4,5,6,7]
Code
1
2
3