Min Operations to Make Alternating Binary String

LeetCode Problem 1758: "Minimum changes to make alternating binary string": You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa. The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not. Return the minimum number of operations needed to make s alternating. Approach: Here are two possibilities, first do not make change in the 1st character and apply rules following it, second consider step of changing the very first character and apply rules following it. The below implementation in Python works on this principle only, simple and straightforward. #Python #LeetCode #Strings #OptimalSolution #CompetitiveProgramming #DataStructures #Algorithms #ProblemSolving

  • graphical user interface

To view or add a comment, sign in

Explore content categories