MAT

Riddle #9

Given a number N, find the adjacent M digits whose product is the highest of all possible combinations.

Given the size of the input, N will be a string. Consult the php manual for arithmetic operations between strings like bcmul or use functions that convert strings into arrays like str_split.

Constraints

1 < M < 10
10M < N < 101000

Esempio

Given the number N = 1563980, if we look for the sequences of M = 4 consecutive digits, we get:

1563, 5639, 6398, 3980

The number whose digit product is greater is the third. Its product is:

1296

Your program

<?php
    
function main($N, $M) {

  $return = 0;
  /* Write your function here */
  
  return $return;
}
  
$IN = (array) json_decode(base64_decode($argv[1]));
extract($IN);
echo main($N, $M);
?>

Your input

{ 
  "N": "1563980",
  "M": 4
}

Your output

-

Correct output

1296

0 0 votes
Article Rating
Notifiche
Notificami
0 Comments
Inline Feedbacks
View all comments