Minimum Moves to Convert String

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Solution:
    def minimumMoves(self, s: str) -> int:
        # Initialize a count for the minimum moves
        moves = 0

        # Iterate through the string
        i = 0
        while i < len(s):
            # If an 'X' is found, make a move and skip the next two characters
            if s[i] == 'X':
                moves += 1
                i += 3
            else:
                i += 1

        # Return the count of moves
        return moves

This function iterates through the string s, and whenever it encounters an ‘X’, it makes a move and skips the next two characters. The process continues until the end of the string, and the total number of moves is returned.