Skip to content

Practice Swap For Longest Repeated Character Substring

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

Medium#1156
LeetCode Problem

Swap For Longest Repeated Character Substring

Problem Statement

You are given a string text. You can swap two of the characters in the text. Return the length of the longest substring with repeated characters.

Source: Swap For Longest Repeated Character Substring on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
text = "ababa"
Output
3

# Example 2

Input
text = "aaabaaa"
Output
6

# Example 3

Input
text = "aaaaa"
Output
5

Constraints

1 <= text.length <= 2 * 10^4
text consist of lowercase English characters only.

Related LeetCode Problems

Practice more problems similar to Swap For Longest Repeated Character Substring.

Review your practice with PhantomCodeAI

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