Created
September 30, 2018 12:38
-
-
Save flymio/6aa5ddf8c1773b05365b8b196421ec95 to your computer and use it in GitHub Desktop.
solution for https://www.hackerrank.com/challenges/mini-max-sum/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
крутое решение на питоне: | |
a = input().strip().split(' ') | |
for i in range(0, len(a)): | |
a[i] = int(a[i]) | |
s = sum(a) | |
print(str(s - max(a)) + " " + str(s - min(a))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Complete the miniMaxSum function below. | |
function miniMaxSum($arr) { | |
global $count; | |
$max=0; $min=0; | |
for($i=1;$i<=$count;$i++){ | |
$sum = getNumber($i)+getNumber($i+1)+getNumber($i+2)+getNumber($i+3); | |
if ($sum>$max){ | |
$max = $sum; | |
} | |
if ($sum < $min || $min == 0){ | |
$min = $sum; | |
} | |
} | |
echo "$min $max\n"; | |
} | |
function getNumber($i){ | |
global $count; | |
global $arr; | |
if (isset($arr[$i])){ | |
return $arr[$i]; | |
} | |
else{ | |
return $arr[$i % $count]; | |
} | |
} | |
$stdin = fopen("php://stdin", "r"); | |
fscanf($stdin, "%[^\n]", $arr_temp); | |
$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY)); | |
$count = count($arr); | |
miniMaxSum($arr); | |
fclose($stdin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment