Minimum Moves to Convert String

You are given a string s consisting of n characters which are either 'X' or 'O'.

A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same.

Return the minimum number of moves required so that all the characters of s are converted to 'O'.

Example 1
Inputs = "XXX"
Output1
We select all the 3 characters and convert them in one move.
Example 2
Inputs = "XXOX"
Output2
We select the first 3 characters in the first move, then select the last 3 characters so that the final string contains all 'O's.

Constraints

  • 3 <= s.length <= 1000
  • s[i] is either 'X' or 'O'.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate