Problem · String
Get Smallest String
Learn this problemProblem statement
Given a string s that consists of lowercase English letters, select exactly one non-empty substring of s and replace each character of it with the previous character of the English alphabet. For example 'b' is converted to 'a', 'c' is converted to 'b'; ..., and 'a' is converted to 'z'.
Find the lexicographically smallest string that can be obtained after performing the above operation exactly once.
Function
getSmallestString(s: String) → String
Complete the function getSmallestString in the editor below.
getSmallestString has the following parameter:
s: string- a string
Returns
string: the lexicographically smallest string possible
Examples
Example 1
s = "hackerrank"return = "gackerrank"Select and change only the first character. Return "gackerrank", the lexicographically smallest string possible.
Example 2
s = "bbcad"return = "aabad"Change bbc to aab.
Constraints
1 ≤ length of
s, |s| ≤ 105More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026