Problem · String
Maximize Consecutive Dance Moves 🩰
Learn this problemProblem statement
A TikTok participant has a binary string s representing a sequence of dance moves. A 0 is a pause and a 1 is a dance move.
The participant must choose exactly k distinct positions and flip each selected character:
0becomes1;1becomes0.
Return the maximum possible number of adjacent 11 pairs after the flips. In other words, count the indices i with 0 <= i < s.length - 1 such that both s[i] and s[i + 1] are 1 in the final string.
Function
maximizeConsecutiveDanceMoves(s: String, k: int) → intExamples
Example 1
s = "01010"k = 2return = 3Flip the first and third characters to obtain 11110. It contains three adjacent 11 pairs, which is maximum.
Constraints
1 <= s.length <= 2000s[i]is0or1.0 <= k <= s.lengths.length * (k + 1) <= 2 * 10^6
More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026