Delete One Digit 5 to Maximize the Number
Updated
Problem statement
You are given an integer n whose decimal representation contains at least one digit 5. Delete exactly one occurrence of that digit, leaving every other digit in its original order.
Return the greatest integer you can obtain. Keep the original sign. Ignore leading zeros after deletion. If no digits remain, the result is 0.
Function
maximizeAfterDeletingFive(n: int) → intExamples
Example 1
n = 15958return = 1958Deleting the first 5 gives 1958; deleting the second gives 1598. The larger result is 1958.
Example 2
n = -5859return = -589The two results are -859 and -589. Since -589 is greater, delete the second 5.
Example 3
n = 5return = 0Deleting the only digit leaves no digits, so return 0.
Constraints
- -99995 <= n <= 99995.
- The decimal representation of the absolute value of n contains at least one digit 5.
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
- Smallest String After at Most One DeletionOA · Seen Jul 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