Skip to content

Instantly share code, notes, and snippets.

@connordavison
Last active October 12, 2015 16:58
Show Gist options
  • Save connordavison/ed5051843dff7fcc623f to your computer and use it in GitHub Desktop.
Save connordavison/ed5051843dff7fcc623f to your computer and use it in GitHub Desktop.
<?php
function solution($A, $B) {
// Build an array relating maximum circumferences to depths
$smallest_at = [-1 => PHP_INT_MAX];
for ($i = 0; $i < count($A); $i++) {
$smallest_at[$i] = min($smallest_at[$i - 1], $A[$i]);
}
// Start dropping
$dropped = 0;
// Reverse our way through the $smallest_at array and attempt to drop
// where possible
for ($i = count($A) - 1; $i >= 0 && $dropped < count($B); $i--) {
if ($smallest_at[$i] >= $B[$dropped]) {
$dropped++;
}
}
return $dropped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment