Company: Factset_9oct
Difficulty: medium
Maximize Equalized Substrings After One Swap Problem Description You're given a string made only of the characters 'L' and 'R' where the total count of 'L' matches the total count of 'R' (an equalized string). You may swap two adjacent characters at most once (or not swap at all). Work out the greatest number of equalized substrings the resulting string can be cut into. Note: An equalized substring is any contiguous part of the string in which the total number of 'L' characters equals the total number of 'R' characters. Return an integer representing this maximum count. Examples Example 1: Input: s = "RLRLLRLRL" Output: 5 Explanation: Swapping the characters at indices 3 and 4 (0-based) changes the string to "RLRLRLRLRL". This updated string can be divided into: "RL", "RL", "RL", "RL", and "RL", each of which is an equalized substring. Hence, the answer is 5. Example 2: Input: s = "LLLLRRRR" Output: 1 Explanation: No single swap can increase the count of equalized substrings, so the en