Skip to content

Instantly share code, notes, and snippets.

@orukusaki
Created October 30, 2013 10:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save orukusaki/bb189d9f69ad09e2cd5a to your computer and use it in GitHub Desktop.
Save orukusaki/bb189d9f69ad09e2cd5a to your computer and use it in GitHub Desktop.
<?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);
}
@bartkappenburg
Copy link

Really nice solution!

@igor47
Copy link

igor47 commented Oct 30, 2013

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