Minimum Changes To Make Alternating Binary String
EasyStringsgreedy
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a string s made of the characters '0' and '1'. In one operation you may flip any single character.
A string is *alternating* if no two adjacent characters are equal, like "0101" or "10101".
Return the minimum number of operations needed to make s alternating.
Examples
Input: s = "0100"
Output: 1
Flip the last character to get "0101".
Input: s = "10"
Output: 0
Already alternating.
Input: s = "1111"
Output: 2
Flip two characters to get "0101" or "1010".
Constraints
- 1 <= s.length <= 10^4
- `s[i]` is either `'0'` or `'1'`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.