Practice Replace the Substring for Balanced String
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'. A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string. Return the minimum length of the substring that can be replaced with any other string of the same length to make s balanced. If s is already balanced, return 0.
Source: Replace the Substring for Balanced String on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "QWER"
0
# Example 2
s = "QQWE"
1
# Example 3
s = "QQQW"
2
Constraints
Related LeetCode Problems
Practice more problems similar to Replace the Substring for Balanced String.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.