Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

This comment has been minimized.

Copy link

commented Oct 30, 2013

Really nice solution!

@igor47

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.