Leetcode 2095 Solution
This article provides solution to leetcode question 2095 (minimum-number-of-swaps-to-make-the-string-balanced)
Access this page by simply typing in "lcs 2095" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced
Solution
class Solution:
def minSwaps(self, s: str) -> int:
level = 0
min_level = 0
for ch in s:
if ch == '[':
level += 1
else:
level -= 1
min_level = min(level, min_level)
return (-min_level + 1) // 2