classSolution: defprevPermOpt1(self, arr: List[int]) -> List[int]: mp = {} a = -1 b = -1 n = len(arr) for i inrange(n-1, -1, -1): for j inrange(i-1, -1, -1): if j <= a: break if arr[j] > arr[i]: a = j b = i if a == -1: return arr else: for j inrange(a, b): if arr[b] == arr[j]: b = j break tmp = arr[a] arr[a] = arr[b] arr[b] = tmp return arr