Meta Data#
Difficulty: easy First Attempt: 2025-03-23
- Submissions: Wrong Answer → Accepted ×2
Approach#
Take the smaller of two limits:
- Cells:
n × n. - Weight: each container weighs
w, so at mostmaxWeight // w(rounded down).
My Attempts#
Attempt 1 used maxWeight / w, returning a float. For n = 2, w = 3, maxWeight = 7 the answer is 2; it returned 2.333.... Wrapping it in int(...) passed; // is clearer.
Solution#
class Solution:
def maxContainers(self, n: int, w: int, maxWeight: int) -> int:
return min(n * n, maxWeight // w)
Complexity#
Time O(1), space O(1).
Mistakes to Avoid#
/is float division in Python 3; counts need//.
Interview Explanation#
The count is limited both by the n² cells and by weight, maxWeight // w, so I take the smaller. Time O(1).
