We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I tried to clone your solution in PHP but I get 8/16 on the test cases. Runtime error on the failed scenarios. I tested the same code on my pc and it goes smoothly, checked unlocking a failed test case and it succed. any hint?
Here's my code:
// Complete the arrayManipulation function below.
function arrayManipulation(queries) {
max = 0;
n, 0);
//$stderr = fopen("php://stderr", "w");
foreach(`$queries as $`i => $query){
`$a = $`query[0];
`$b = $`query[1];
`$k = $`query[2];
if($a-1>=0){
`$result_array[$`a-1] += $k;
}
else{
var_dump(" a - 1 is negative! ".$a);
}
if(`$b < $`n){
`$result_array[$`b] -= $k;
}
else{
var_dump(" b is too big! ".$b);
}
//echo implode(" ", $result_array)."\n";
//fwrite(`$stderr, implode(" ", $`result_array)."\n");
}
foreach(`$result_array as $`value){
`$sum += $`value;
`$max = max($`sum, $max);
}
//echo($max);
//fwrite(`$stderr, $`max);
//fclose($stderr);
return $max;
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf(nm_temp);
nm_temp);
nm[0]);
nm[1]);
$queries = array();
for (i < i++) {
fscanf(queries_temp);
queries_temp, -1, PREG_SPLIT_NO_EMPTY));
}
n, $queries);
fwrite(result . "\n");
fclose(fptr);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
I tried to clone your solution in PHP but I get 8/16 on the test cases. Runtime error on the failed scenarios. I tested the same code on my pc and it goes smoothly, checked unlocking a failed test case and it succed. any hint? Here's my code:
// Complete the arrayManipulation function below. function arrayManipulation(queries) { max = 0; n, 0); //$stderr = fopen("php://stderr", "w");
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf(nm_temp); nm_temp);
nm[0]);
nm[1]);
$queries = array();
for (i < i++) { fscanf(queries_temp); queries_temp, -1, PREG_SPLIT_NO_EMPTY)); }
n, $queries);
fwrite(result . "\n");
fclose(fptr);