FunctionRacerProblemsRace

Largest Digit

BeginnerRecursionPython, JavaScript, TypeScript, Java, C++

Return the largest decimal digit that appears in the non-negative integer n.

For example, 2734 is written with the digits 2, 7, 3 and 4, so the answer is 7. A number below 10 is its own answer, so n = 0 gives 0.

Example 1

n 2734
returns 7

The digits are 2, 7, 3 and 4; the largest is 7.

Example 2

n 5
returns 5

A single digit is its own largest digit.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems