USACO 2019 February Contest, Silver Problem 1. Sleepy Cow Herding
This is USACO 2019 February Contest, Silver, Problem 1. Sleepy Cow Herding\n\nIt\'s medium, if you\'re in the contest :)\n\nHow to solve it? https://www.youtube
This is [USACO 2019 February Contest, Silver, Problem 1. Sleepy Cow Herding](]https://usaco.org/index.php?page=viewproblem2&cpid=918)\n\nIt\'s medium, if you\'re in the contest :)\n\nHow to solve it? https://www.youtube.com/watch?v=BvgV7f3pwcI\n\n```\nclass Solution:\n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        N = len(stones)\n        stones.sort()\n        min_res = 0\n        if stones[N - 2] - stones[0] == N - 2 and stones[N - 1] - stones[N - 2] > 2:\n            min_res = 2\n        elif stones[N - 1] - stones[1] == N - 2 and stones[1] - stones[0] > 2:\n            min_res = 2\n        else:\n            l = r = max_range = 0\n            while l < N:\n                while r < N - 1 and stones[r + 1] - stones[l] <= N - 1:\n                    r += 1\n                max_range = max(max_range, r - l + 1)\n                l += 1\n            min_res = N - max_range\n        max_res = max(stones[N - 2] - stones[0], stones[N - 1] - stones[1]) - (N - 2)\n        return (min_res, max_res)\n```
['Python', 'Python3']