Longest Increasing Run
PHP
Hard
6 views
Problem Description
Given n integers, find the length of the longest strictly increasing contiguous run.
Input Format
First n. Next line n ints.
Output Format
One integer length.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
if($n<=0){ echo 0; exit; }
$prev=intval($tokens[$i++] ?? 0);
$cur=1; $best=1;
for($k=1;$k<$n;$k++){
$v=intval($tokens[$i++] ?? 0);
if($v>$prev) $cur++; else $cur=1;
if($cur>$best) $best=$cur;
$prev=$v;
}
echo $best;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!