Smallest String After at Most One Deletion
Updated
Problem statement
Given a nonempty lowercase string s, delete at most one character while preserving the order of all other characters.
Return the lexicographically smallest possible string. Compare at the first different character; if one string is a prefix of the other, the shorter string is smaller. The empty string is allowed as a result.
Function
smallestAfterDeletion(s: String) → StringExamples
Example 1
s = "abcda"return = "abca"Remove d from abcda to obtain abca. Deleting any earlier character makes the first differing character larger.
Example 2
s = "aaa"return = "aa"Deleting any one a gives aa, a shorter prefix of aaa.
Example 3
s = "a"return = ""Deleting the only character gives the empty string, which is smaller than a.
Constraints
- 1 <= s.length <= 100000.
- s contains only lowercase English letters.
More LSEG Online Assessment questions
- Count Times Using at Most Two DigitsOA · Seen Jul 2025
- Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
- Maximum Word Count in a SentenceOA · Seen Jul 2025
- Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
- Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
- Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
- Transform a String with at Most One OperationOA · Seen Feb 2025
- Price Equity Options and ForwardsOA · Seen Dec 2024
- Maximum Sum of Non-Adjacent ElementsOA · Seen Sep 2024
- Return the Sentence with the Most WordsOA · Seen Sep 2024
Similar questions at other companies
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Prepare NotificationMicrosoft · OAMicrosoft interview questions
- Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
- Largest Number With Even Digit FrequenciesDRW · OADRW interview questions
- Minimum Replacements for Unequal Adjacent CharactersIBM · OAIBM interview questions
- Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions
- Minimum Flips for Even Binary RunsJP Morgan Chase · OAJP Morgan Chase interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions