Lexicographically Smallest String

Given a string str, the task is to find the lexicographically smallest string that can be formed by removing at most one character from the given string.

Example 1:

Input: abczd

Output: abcd

Example 2:

Input: abcda

Output: abca

Explanation:

One can remove d to get abca which is the lexicographically smallest string possible.

Try it yourself

Implementation

1
1
def smallestString(s) -> str:
2
-
      # WRITE YOUR BRILLIANT CODE HERE
2
+
      for i in range(len(s) - 1):
3
+
          if s[i] > s[i + 1]:
4
+
              break
5
+
      return s[:i]+s[i+1:]
6
+
3
7
if __name__ == '__main__':
4
8
    print(smallestString(input()))