Maximum Blocks in a Constrained Cave
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[]) → intExamples
Example 1
blockHeights = [4,2,3]caveHeights = [3,5]return = 2Place height 2 in capacity 3 and height 3 or 4 in capacity 5.
Constraints
- Each array contains at most
10^5positive heights.