Skip to content

Practice Smallest Substring With Identical Characters II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3399
LeetCode Problem

Smallest Substring With Identical Characters II

Problem Statement

Given a binary string s and numOps, you may flip at most numOps individual bits. Return the minimum achievable length of the longest contiguous run of identical bits after these changes.

Source: Smallest Substring With Identical Characters II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "000001", numOps = 1
Output
2

# Example 2

Input
s = "0000", numOps = 2
Output
1

# Example 3

Input
s = "0101", numOps = 0
Output
1

Constraints

1 <= n == s.length <= 10^5
s consists only of '0' and '1'.
0 <= numOps <= n

Related LeetCode Problems

Practice more problems similar to Smallest Substring With Identical Characters II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.