A TikTok participant is engaging in a challenge where they have a binary string representing a sequence of dance moves. The string consists of 0s and 1s , with 0s signifying pauses and 1s representing dance moves.
The participant can choose exactly k distinct positions in the string to modify. These modifications involve flipping the moves at those positions, converting 0s to 1s and 1s to 0s.
The objective is to maximize the count of pairs of consecutive dance moves (1s) in the final dance sequence. In TikTok challenges, participants aim to create the smoothest dance transitions.
Your task is to assist the participant in determining the maximum possible number of pairs of consecutive dance moves (1s) in the final dance sequence after the allowable adjustments.
Note that the count of pairs of consecutive 1s represents the number of indices i (1 ≤ i < n ) where s[i] = '1' and s[i+1] = '1', showcasing the seamless dance transitions in the challenge.
Example 1 :
Input: s = "01010", k = 2
Output: 3
Explanation:
Following are some possible selection of positions in s:
If we choose 1
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.