#2027
Minimum Moves to Convert String
pupil · 405 · lc easy +24 · verified · 57.7% accepted · 536 likes · top 53%
Description
Given a string s of 'X' and 'O' characters, one move selects any three consecutive positions and sets all of them to 'O'. Return the minimum number of such moves needed to make every character in s equal to 'O'.
Example 1:
Input: s = "XXX"
Output: 1
Explanation: XXX -> OOO
We select all the 3 characters and convert them in one move.
Example 2:
Input: s = "XXOX"
Output: 2
Explanation: XXOX -> OOOX -> OOOO
We select the first 3 characters in the first move, and convert them to 'O'.
Then we select the last 3 characters and convert them so that the final string contains all 'O's.
Example 3:
Input: s = "OOOO"
Output: 0
Explanation: There are no 'X's in s to convert.
Code
1
2
3