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.
Input: str = "abcda" Output: abca One can remove 'd' to get "abca" which is the lexicographically smallest string possible. Input: str = "aaa' Output: aa
Approach: Traverse the string and delete the i-th character at the first point where s[i]>s[i+1]. If in case there is no such character then delete the last character in the string.
Below is the implementation of the above approach:
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
- Find a string such that every character is lexicographically greater than its immediate next character
- Lexicographically largest string formed from the characters in range L and R
- Find longest palindrome formed by removing or shuffling chars from string
- Lexicographically next greater string using same character set
- Character replacement after removing duplicates from a string
- Lexicographically smallest string whose hamming distance from given string is exactly K
- Lexicographically smallest string of length N and sum K
- Minimize the length of string by removing occurrence of only one character
- Queries to answer the X-th smallest sub-string lexicographically
- Lexicographically smallest permutation of a string with given subsequences
- K-th lexicographically smallest unique substring of a given string
- Minimum sum of squares of character counts in a given string after removing k characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.