Suppose we have a string s, this string consisting of "R" and "L", we have to remove the minimum number of characters such that there's no consecutive "R" and no consecutive "L".
So, if the input is like "LLLRLRR", then the output will be "LRLR"
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, s): seen = s ans = s for i in s[1:]: if i != seen: ans += i seen = i return ans ob = Solution() print(ob.solve("LLLRLRR"))