# 1560. Most Visited Sector in a Circular Track # @param {Integer} n # @param {Integer[]} rounds # @return {Integer[]} def most_visited(n, rounds) uses = Array.new(n+1, 0) i = 0 while i < (rounds.size()-1) x = rounds[i] tgt = rounds[i+1] while x != tgt uses[x] += 1 x = x+1 > n ? 1 : x+1 end i += 1 end uses[rounds[-1]] += 1 max_amount = 0 i = 1 while i < uses.size() if uses[i] > max_amount max_amount = uses[i] end i += 1 end res = [] i = 1 while i < uses.size() if uses[i] == max_amount res.push(i) end i += 1 end res end def main() puts String(most_visited(4, [1, 3, 1, 2]) == [1,2]) puts String(most_visited(2, [2,1,2,1,2,1,2,1,2]) == [2]) puts String(most_visited(7, [1,3,5,7]) == [1,2,3,4,5,6,7]) end if __FILE__ == $0 main() end