Skip to the content

The key of the day

Problem

"Today's key is hidden in the number," says the message Agent Nieves receives. Her spy network has one fixed rule: the key is the highest digit that appears in the number of the day.

Write a function that takes a whole number and returns its highest digit, as a whole number. With 4192 the digits are 4, 1, 9 and 2: you return 9. The number can be negative, and the sign is not a digit: in -507 the digits are 5, 0 and 7, so you return 7. If the highest digit repeats, you return it once: 5525 gives 5. And 0 has a single digit, 0, so it returns 0.

Examples

  • Highest comes in the middle

    4192 → 9

  • Highest comes first

    8123 → 8

  • Highest comes last

    1237 → 7

  • A single digit

    6 → 6

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def highest_digit(n):
    pass

JavaScript

function highestDigit(n) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(log n) challenges

See all challenges →