Skip to content

Practice Minimum Cost Good Caption

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

Hard#3441
LeetCode Problem

Minimum Cost Good Caption

Problem Statement

A good caption has every maximal run of a single character at least three characters long. One operation changes one letter of caption to its immediate alphabet predecessor or successor, without wrapping beyond a or z. Return a good caption requiring the fewest operations, breaking ties lexicographically. If none exists, return the empty string.

Source: Minimum Cost Good Caption on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
caption = "cdcd"
Output
"cccc"

# Example 2

Input
caption = "aca"
Output
"aaa"

# Example 3

Input
caption = "bc"
Output
""

Constraints

1 <= caption.length <= 5 * 10^4
caption consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Cost Good Caption.

Review your practice with PhantomCodeAI

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