easy peasy numpy squeezy
Brute force, gets accepted in about 1650 ms:\n\n    def bestRotation(self, A):\n        n = len(A)\n        a = np.array(2 * A)\n        nr = np.arange(n)\n    
Brute force, gets accepted in about 1650 ms:\n\n    def bestRotation(self, A):\n        n = len(A)\n        a = np.array(2 * A)\n        nr = np.arange(n)\n        return max(range(n), key=lambda k: np.count_nonzero(a[k:k+n] <= nr))\n\nOptimized version, gets accepted in about 550 ms:\n\n    def bestRotation(self, A):\n        n = len(A)\n        a = np.array(2 * A, dtype=\'int16\')\n        nr = np.arange(n, dtype=\'int16\')\n        return max(range(n), key=lambda k: np.count_nonzero(a[k:k+n] <= nr))
[]