prefixSums and suffixSums, to store the cumulative cost of inverting characters from the start and from the end of the string, respectively.prefixSums with the cost of inverting characters up to the current index whenever a character is different from its predecessor.suffixSums with the cost of inverting characters from the current index to the end of the string whenever a character is different from its successor.minCost to a large value to keep track of the minimum cost found so far.minCost with the smaller of the current cost and the previously stored minCost.minCost as the final answer.