-
-
Save orukusaki/bb189d9f69ad09e2cd5a to your computer and use it in GitHub Desktop.
Quick solution to http://qandwhat.apps.runkite.com/i-failed-a-twitter-interview/
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 | |
function fill(array $in) | |
{ | |
foreach ($in as $i => $h) { | |
$m[$i] = max( | |
min( | |
array_reduce(array_slice($in, 0, $i), 'max'), | |
array_reduce(array_slice($in, $i), 'max') | |
) - $h, | |
0 | |
); | |
} | |
return array_sum($m); | |
} |
what's the runtime? it's not quite clear how many times this walks bath and forth down the array, but it's definitely not linear.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really nice solution!