Minimum in Matrix
PHP
Medium
5 views
Problem Description
Given r and c and the matrix values, print the minimum value.
Input Format
First r c. Next r*c integers.
Output Format
One integer minimum.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0;
$r=intval($tokens[$i++] ?? 0);
$c=intval($tokens[$i++] ?? 0);
$mn=null;
for($k=0;$k<$r*$c;$k++){
$v=intval($tokens[$i++] ?? 0);
if($mn===null || $v<$mn) $mn=$v;
}
echo ($mn===null?0:$mn);
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!