MCPcopy Create free account
hub / github.com/Rohit91singh9/Coding-DP-DSA / minimumSwapsRequired

Function minimumSwapsRequired

minimumSwapsRequired.py:2–10  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

1
2def minimumSwapsRequired(string):
3 n = len(string)
4 num = 0
5 for i in range(n // 2):
6 if string[i] != string[n - i - 1]:
7 num += 1
8 if num % 2 == 1 and n % 2 == 0:
9 return -1
10 return (num + 1) // 2
11
12print(minimumSwapsRequired("101000"))
13

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected