FastPrepMaximum Blocks in a Constrained Cave

Maximum Blocks in a Constrained Cave

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Each block has unit width and fixed height. Each cave position has unit width and maximum height caveHeights[j]. Assign at most one block to each position; a block fits when its height is at most the position capacity.

Return the maximum number of blocks that can be placed. Blocks cannot rotate or stack.

Function

maximumCaveBlocks(blockHeights: int[], caveHeights: int[]) → int

Examples

Example 1

blockHeights = [4,2,3]caveHeights = [3,5]return = 2

Place height 2 in capacity 3 and height 3 or 4 in capacity 5.

Constraints

  • Each array contains at most 10^5 positive heights.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int maximumCaveBlocks(int[] blockHeights, int[] caveHeights) {
  // Write your code here.
}
blockHeights[4,2,3]
caveHeights[3,5]
expected2
Checking account…