1560. Most Visited Sector in a Circular Track Easy

@problem@discussion
#Array#Simulation



1/**
2 * [1560] Most Visited Sector in  a Circular Track
3 *
4 * 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]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]
5 * Return an array of the most visited sectors sorted in ascending order.
6 * Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/14/tmp.jpg" style="width: 433px; height: 341px;" />
10 * Input: n = 4, rounds = [1,3,1,2]
11 * Output: [1,2]
12 * Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:
13 * 1 --> 2 --> 3 (end of round 1) --> 4 --> 1 (end of round 2) --> 2 (end of round 3 and the marathon)
14 * 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.
15 * Example 2:
16 * 
17 * Input: n = 2, rounds = [2,1,2,1,2,1,2,1,2]
18 * Output: [2]
19 * 
20 * Example 3:
21 * 
22 * Input: n = 7, rounds = [1,3,5,7]
23 * Output: [1,2,3,4,5,6,7]
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	2 <= n <= 100
29 * 	1 <= m <= 100
30 * 	rounds.length == m + 1
31 * 	1 <= rounds[i] <= n
32 * 	rounds[i] != rounds[i + 1] for 0 <= i < m
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/most-visited-sector-in-a-circular-track/
38// discuss: https://leetcode.com/problems/most-visited-sector-in-a-circular-track/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn most_visited(n: i32, rounds: Vec<i32>) -> Vec<i32> {
44        vec![]
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_1560() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.