Python3 Faster than 95% w Explanation
Difficulty of this question comes more from the UNDERSTANDING the question more than ANSWERING the question. It should be better phrased. Nevertheless...\n\nExp
Difficulty of this question comes more from the UNDERSTANDING the question more than ANSWERING the question. It should be better phrased. Nevertheless...\n\n**Explanation**\nImagine a 3 part race with running(1), biking(2) and swimming(3) components.\n\nIf the race states they start with running (1) and finish with swimming (3), the racer will run (1), bike(2), then swim(3) to finish the circuit.\n\nIf the race mandates they start with biking(2) and finish with running(1), the racer will bike(2), swim(3), then run(1).\n\nIf the race mandates they start with biking(2) and finish with swimming(3), the racer will bike(2) then swim(3). No need for the racer to run(1).\n\n```n``` in the question determines how many components to the race.\n```rounds[i-1]``` to ```rounds[i]``` in the question states the circuit the racer has to run. (e.g running(1) to swimming(3) )\n\n**Case 1:**\nRacer starts and finishes at different components e.g ```rounds = [1, 3]```\nAll components ran once. So answer is ```[1, 2, 3]```\n\n**Case 2:**\nRacer starts and finishes at the same component e.g ```rounds = [1,3,1]```\nRacer has completed running(1) twice. biking(2) and swimming(3) have been completed once. So answer is ```[1]```\n\n**Case 3:**\nRacer starts and finishes at different components BUT starting component is "later" than the finishing point e.g ```rounds = [3,1]```\nRacer starts swiming(3), then goes running (1). Racer does not bike(2).\nSo answer is ```[1, 3]```\n\nSince this race is a circuit, all the components in the middle don\'t matter. We only look at the start and end points. ```rounds = [3, 1, 2, 3, 1]``` will give you the same answer as ```rounds = [3,1]```\nBoth answers are ```[1, 3]```\n\n```\nclass Solution:\n    def mostVisited(self, n: int, rounds: List[int]) -> List[int]:\n        if rounds[0] == rounds[-1]: #case 2\n            return [rounds[0]]\n        if rounds[0] < rounds[-1]: #case 1\n            return [x for x in range (rounds[0], rounds[-1]+1)]\n        else: #case 3\n            return [x for x in range (1, rounds[-1] + 1)] + [x for x in range (rounds[0], n + 1)]\n        \n```\n\n
[]