Ctrl K

Crates on a Square Deck

Easy
A ship's cargo deck is a square of side × side cells. Each cell holds at most one crate, and every crate weighs exactly weight. The total weight of the loaded crates must not exceed the ship's capacity capacity. Return the largest number of crates that can be loaded.
Example 1
side=3, weight=4, capacity=50 → 9

The deck has 9 cells, and all 9 crates weigh 36, which is within 50.

Example 2
side=4, weight=7, capacity=30 → 4

There are 16 cells, but 5 crates would weigh 35 > 30, so only 4 fit.

Example 3
side=1, weight=10, capacity=9 → 0
Constraints
  • 1 ≤ side ≤ 1000
  • 1 ≤ weight ≤ 1000
  • 1 ≤ capacity ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
side=3, weight=4, capacity=50
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.