Most Visited Sector in a Circular Track — LeetCode 1560 Python Solution
EasyArraySimulation
- Problem
- #1560
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n.
Example
- 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:
Python solution
Python
class Solution:
def mostVisited(self, n: int, rounds: List[int]) -> List[int]:
if rounds[0] <= rounds[-1]:
return list(range(rounds[0], rounds[-1] + 1))
return list(range(1, rounds[-1] + 1)) + list(range(rounds[0], n + 1))Complexity
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the number of sectors |
| Space | O(1) auxiliary |
Related problems
LeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMedium
Frequently asked questions
- How hard is LeetCode 1560. Most Visited Sector in a Circular Track?
- LeetCode 1560. Most Visited Sector in a Circular Track is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1560. Most Visited Sector in a Circular Track?
- The Python solution on this page runs in O(n), where n is the number of sectors.
- What is the space complexity of LeetCode 1560. Most Visited Sector in a Circular Track?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 1560. Most Visited Sector in a Circular Track cover?
- LeetCode 1560. Most Visited Sector in a Circular Track is tagged Array and Simulation on LeetCode.