Leetcode Problem 2734. Lexicographically Smallest String After Substring Operation

2734. Lexicographically Smallest String After Substring Operation

Leetcode Solutions

Find the First Non-'a' Character Approach

  1. Iterate through the characters of the string s.
  2. If the current character is 'a', continue to the next character.
  3. If the current character is not 'a', replace it with its previous character in the alphabet.
  4. Continue replacing each character to the left of this character.
  5. If the operation has been performed, return the modified string.
  6. If no operation has been performed (the string was all 'a's), replace the last character with 'z' and return the string.
UML Thumbnail

Replace from First 'a' Substring Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...