Description
Solutions
Get Smallest String
🔥 FULLTIME

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 Description

Complete the function getSmallestString in the editor below.

getSmallestString has the following parameter:

  • s: string - a string

Returns

string: the lexicographically smallest string possible

Example 1:

Input:  s = "hackerrank"
Output: "gackerrank"
Explanation:
Select and change only the first character. Return "gackerrank", the lexicographically smallest string possible.

Example 2:

Input:  s = "bbcad"
Output: "aabad"
Explanation:
Change bbc to aab.
Constraints:
    1 ≤ length of s, |s| ≤ 105
Thumbnail 0
Testcase

Result
Case 1

input:

output: