8000 Add 3492_maximum_containers_on_a_ship · m3xw3ll/LeetCode@5b9cb90 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b9cb90

Browse files
committed
Add 3492_maximum_containers_on_a_ship
1 parent 221fd42 commit 5b9cb90

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Maximum Containers on a Ship](https://leetcode.com/problems/maximum-containers-on-a-ship/description/)
2+
3+
You are given a positive integer n representing an n x n cargo deck on a ship. Each cell on the deck can hold one container with a weight of exactly w.
4+
5+
However, the total weight of all containers, if loaded onto the deck, must not exceed the ship's maximum weight capacity, maxWeight.
6+
7+
Return the maximum number of containers that can be loaded onto the ship.
8+
9+
Example 1:
10+
```
11+
Input: n = 2, w = 3, maxWeight = 15
12+
13+
Output: 4
14+
15+
Explanation:
16+
17+
The deck has 4 cells, and each container weighs 3. The total weight of loading all containers is 12, which does not exceed maxWeight.
18+
```
19+
Example 2:
20+
```
21+
Input: n = 3, w = 5, maxWeight = 20
22+
23+
Output: 4
24+
25+
Explanation:
26+
27+
The deck has 9 cells, and each container weighs 5. The maximum number of containers that can be loaded without exceeding maxWeight is 4.
28+
```
29+
Solution
30+
```python
31+
class Solution:
32+
def maxContainers(self, n: int, w: int, maxWeight: int) -> int:
33+
return min(n*n, maxWeight // w)
34+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def max_containers(n, w, max_weight):
2+
return min(n*n, max_weight // w)
3+
4+
5+
print(max_containers(n = 2, w = 3, max_weight = 15))

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ To search for a specific problem please use ```STRG + F``` to search for.
778778
| 3461 | [Check If Digits Are Equal in String After Operations I](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/3461_check_if_digits_are_equal_in_string_after_operations_one.md)
779779
| 3467 | [Transform Array by Parity](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/3467_transform_array_by_parity.md)
780780
| 3483 | [Unique 3-Digit Even Numbers](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/3483_unique_three_digit_even_numbers.md)
781-
781+
| 3492 | [Maximum Containers on a Ship](https://github.com/m3xw3ll/LeetCode/blob/master/Algorithms/3492_maximum_containers_on_a_ship.md)
782782

783783

784784
### Pandas

0 commit comments

Comments
 (0)
0