Skip to content

Practice Lexicographically Smallest String After Operations With Constraint

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

Medium#3106
LeetCode Problem

Lexicographically Smallest String After Operations With Constraint

Problem Statement

Given a lowercase string s and an integer k, return the lexicographically smallest string t of the same length whose distance from s is at most k. The distance is the sum of the distances between corresponding letters. For two letters, use the shorter distance around the circular alphabet, where a and z are adjacent.

Source: Lexicographically Smallest String After Operations With Constraint on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "zbbz", k = 3
Output
"aaaz"

# Example 2

Input
s = "xaxcd", k = 4
Output
"aawcd"

# Example 3

Input
s = "lol", k = 0
Output
"lol"

Constraints

1 <= s.length <= 100
0 <= k <= 2000
s consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Lexicographically Smallest String After Operations With Constraint.

Review your practice with PhantomCodeAI

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