Hard? Another day to use the editorial

I used a sliding window technique to maintain a subarray where all the elements are unique. I kept a set called seen to quickly check for duplicates and removed elements from the left of the window if a duplicate was encountered. For each unique window, I maintained the sum and updated the maximum sum encountered so far.
It didn't work and I checked the editorial, and it was a one-liner???
I decided to always prioritize removing the more valuable pattern first—either "ab" or "ba"—depending on which of x or y is greater. I wrote a helper function remove_pattern that simulates the removal of the given pattern using a stack. It loops through each character and checks whether the top of the stack and the current character form the desired pattern. If they do, I remove the top and add the pattern’s value to the score. I run this function twice: once for the higher-value pattern and again for the other on the updated string.
class Solution:
def maximumGain(self, s: str, x: int, y: int) -> int:
I used a sliding window technique with a set to keep track of the unique elements in the current window using two pointers: left and right. As I moved right through the array, I kept adding elements to a running sum and to the set. If I encountered a duplicate element (i.e., one already in the set), I slid the left pointer forward and removed elements from the set and subtracted their values from the sum until the duplicate was removed. At each step, I updated the maximum sum I could get.
class Solution:
def maximumUniqueSubarray(self, nums: List[int]) -> int:
I iterated through the string character by character while building a new result string. I kept track of the last two characters in the result. If the current character is the same as the last two added characters, I skipped it because adding it would create three consecutive identical characters, which violates the "fancy" condition. Otherwise, I added the character to the result.
class Solution:
def makeFancyString(self, s: str) -> str:
I first sorted the list of folders in lexicographical order. This way, all potential parent folders come before their subfolders. Then, I iterated through the sorted list and maintained a result list. For each folder, I checked whether it starts with the last added folder in the result list followed by a /. If it does, that means it's a subfolder and should be skipped. Else, I added it to the result.
class Solution:
def removeSubfolders(self, folder: List[str]) -> List[str]: