Code Lab

Largest two-digit number

EasyStrings7 min

The input is a string of digits, at least two characters long. Write a function maxTwoDigit(digits) that finds the largest number made of two neighbouring digits and returns it as a number.

Examples

maxTwoDigit('34987')

Returns 98

The pairs are 34, 49, 98 and 87.
maxTwoDigit('1205')

Returns 20

Only neighbouring digits are taken.
maxTwoDigit('05')

Returns 5

The pair 05 is the number 5.

Asked at Druva · Source

Loading the editor...
  1. InputmaxTwoDigit('34987')
    Expected98
  2. InputmaxTwoDigit('1205')
    Expected20
  3. InputmaxTwoDigit('05')
    Expected5

Hidden tests run on Submit.