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 array formed by at most one swap for every pair of adjacent indices
- Lexicographically smallest string formed by removing duplicates
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest subsequence possible by removing a character from given string
- Lexicographically smaller string by swapping at most one character pair
- Find lexicographically smallest string in at most one swaps
- Make the string lexicographically smallest and non palindromic by replacing exactly one character
- Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
- Find a string such that every character is lexicographically greater than its immediate next character
- Count of strings that can be formed from another string using each character at-most once
- Print the last character of lexicographically smallest non-palindromic permutation of a string
- Find the lexicographically smallest sequence which can be formed by re-arranging elements of second array
- Minimize the length of string by removing occurrence of only one character
- Lexicographically smallest array after at-most K consecutive swaps
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Count of substrings having the most frequent character in the string as first character
- Minimize ASCII values sum after removing all occurrences of one character
- Check if a string can be formed from another string by at most X circular clockwise shifts
- Lexicographically smallest string whose hamming distance from given string is exactly K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.