Skip to content

Commit e95fb81

Browse files
committed
adding minimum swap
1 parent 10ec3f7 commit e95fb81

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
3+
4+
class Solution:
5+
def minSwaps(self, data: List[int]) -> int:
6+
k = sum(data) # window size
7+
ans = val = 0
8+
for i, x in enumerate(data):
9+
val += x
10+
if i >= k: val -= data[i-k]
11+
if i+1 >= k: ans = max(ans, val)
12+
return k - ans

0 commit comments

Comments
 (0)