Tap here to switch tabs
Problem
Submissions

Problem: Put Boxes Into the Warehouse I

med
30 min
Try to solve the Put Boxes Into the Warehouse I problem.

Statement

You are given two arrays of positive integers, boxes and warehouse, representing the heights of several boxes and the heights of nn rooms in a warehouse, respectively. The rooms in the warehouse are indexed from 00 to n−1n - 1 from left to right, where warehouse[i] is the height of the iextthi^{ ext{th}} room.

Boxes can only be moved into the warehouse from left to right. A box can be placed in room ii if:

  • The height of the box is less than or equal to the height of room ii, and

  • The height of the box is less than or equal to the heights of all preceding rooms from room 00 to room i−1i - 1, since it must pass through them.

Each room can hold at most 11 box. Once a box is placed in a room, other boxes cannot pass through that room.

Return the maximum number of boxes that can be placed in the warehouse.

Constraints:

  • n ==== warehouse.length

  • 1≤1 \leq boxes.length, warehouse.length ≤105\leq 10^5

  • 1≤1 \leq boxes[i], warehouse[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Put Boxes Into the Warehouse I

med
30 min
Try to solve the Put Boxes Into the Warehouse I problem.

Statement

You are given two arrays of positive integers, boxes and warehouse, representing the heights of several boxes and the heights of nn rooms in a warehouse, respectively. The rooms in the warehouse are indexed from 00 to n−1n - 1 from left to right, where warehouse[i] is the height of the iextthi^{ ext{th}} room.

Boxes can only be moved into the warehouse from left to right. A box can be placed in room ii if:

  • The height of the box is less than or equal to the height of room ii, and

  • The height of the box is less than or equal to the heights of all preceding rooms from room 00 to room i−1i - 1, since it must pass through them.

Each room can hold at most 11 box. Once a box is placed in a room, other boxes cannot pass through that room.

Return the maximum number of boxes that can be placed in the warehouse.

Constraints:

  • n ==== warehouse.length

  • 1≤1 \leq boxes.length, warehouse.length ≤105\leq 10^5

  • 1≤1 \leq boxes[i], warehouse[i] ≤109\leq 10^9