FastPrepRemove One Five for the Largest Number
Problems/Remove One Five for the Largest Number

Remove One Five for the Largest Number

Cohere logoCohere● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Cohere intern online assessment report gives the input as a string of digits, several choices of which digit 5 to remove, and the goal of the largest value. We added standard formatting for signed integers and limits. Our version is about 93% the same as the reported question.

You are given an integer written as a string number. Remove exactly one digit 5 from it. Return the largest integer you can get, also written as a string.

The input may begin with -, which means it is negative. Write the result the normal way, with no leading zeros. Return 0 when every remaining digit is zero or no digit remains.

Function

removeOneFive(number: String) → String

Examples

Example 1

number = "5456"return = "546"

Removing the first 5 gives 456; removing the second gives 546, which is larger.

Example 2

number = "-5155"return = "-155"

The number is negative, so the largest result is the one closest to zero. Removing the first five leaves a number that starts with one. Removing either of the last two fives leaves a number that starts with five, which is further below zero. So the answer comes from removing the first five.

Constraints

  • 1 <= number.length <= 17.
  • number is a valid integer written the normal way, with no plus sign and no leading zeros. It contains at least one digit 5.
  • The result fits in a signed 64-bit integer.

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
See Cohere hiring insights
Saved
class Solution {
    public String removeOneFive(String number) {
        // Remove exactly one digit 5 and return the largest integer.
    }
}
Checking account…