I'm trying to solve one simple task and on first look it's working.
Any advice on how I can optimize this code will be appreciated.
A quick description of the task would be:
You have a file from which you read the integers.
The first line has two values:
- The array width
- The number of test cases
The second line has actual array values.
After that, you have \$N\$ rows all containing the array range which should be checked.
\$N =\$ the number of test cases.
Here's a link to my code
<?php
$handle = fopen("php://stdin", "r");
$getFirstRow = fgets($handle);
$firstrow = explode(" ", $getFirstRow);
$firstrow1 = intval($firstrow[0]);
$firstrow2 = intval($firstrow[1]);
$getString = fgets($handle);
for ($z=0;$z<$firstrow2;$z++)
{
$getRange = fgets($handle);
$getRagearr = explode(" ", $getRange);
$i=intval($getRagearr[0]);
$j=intval($getRagearr[1]);
$arrResult = array();
$lane = explode(" ", $getString);
for ($p=$i;$p<=$j;$p++)
{
array_push($arrResult, $lane[$p]);
}
$result = min($arrResult);
echo $result.PHP_EOL;
}