Tap here to switch tabs
Problem
Submissions

Problem: Replace the Substring for Balanced String

med
30 min
Try to solve the Replace the Substring for Balanced String problem.

Statement

You are given a string s of length n containing only the characters 'Q', 'W', 'E', and 'R'.

A string is called balanced if each of these 44 characters appears exactly n // 44 times.

Return the minimum length of a contiguous substring that can be replaced with any arbitrary string of the same length to make s balanced. If s is already balanced, return 00.

Constraints:

  • n ==== s.length

  • 4≤4 \leq n ≤105\leq 10^5

  • n is a multiple of 44

  • s contains only 'Q', 'W', 'E', and 'R'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Replace the Substring for Balanced String

med
30 min
Try to solve the Replace the Substring for Balanced String problem.

Statement

You are given a string s of length n containing only the characters 'Q', 'W', 'E', and 'R'.

A string is called balanced if each of these 44 characters appears exactly n // 44 times.

Return the minimum length of a contiguous substring that can be replaced with any arbitrary string of the same length to make s balanced. If s is already balanced, return 00.

Constraints:

  • n ==== s.length

  • 4≤4 \leq n ≤105\leq 10^5

  • n is a multiple of 44

  • s contains only 'Q', 'W', 'E', and 'R'