Skip to content

Commit 033d5e4

Browse files
add 3074
1 parent ca3dea5 commit 033d5e4

File tree

3 files changed

+51
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+51
-0
lines changed

Diff for: paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| 3120 | [Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3120.java) | | Easy |
3131
| 3110 | [Score of a String](https://leetcode.com/problems/score-of-a-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3110.java) | | Easy |
3232
| 3095 | [Shortest Subarray With OR at Least K I](https://leetcode.com/problems/shortest-subarray-with-or-at-least-k-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3095.java) | | Easy |
33+
| 3074 | [Apple Redistribution into Boxes](https://leetcode.com/problems/apple-redistribution-into-boxes/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3074.java) | | Easy |
3334
| 3062 | [Winner of the Linked List Game](https://leetcode.com/problems/winner-of-the-linked-list-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3062.java) | | Easy |
3435
| 3046 | [Split the Array](https://leetcode.com/problems/split-the-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3046.java) | | Easy |
3536
| 3042 | [Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3042.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.Arrays;
4+
5+
public class _3074 {
6+
public static class Solution1 {
7+
public int minimumBoxes(int[] apple, int[] capacity) {
8+
int apples = 0;
9+
for (int app : apple) {
10+
apples += app;
11+
}
12+
Arrays.sort(capacity);
13+
int boxes = 0;
14+
for (int i = capacity.length - 1; i >= 0; i--) {
15+
boxes++;
16+
apples -= capacity[i];
17+
if (apples <= 0) {
18+
return boxes;
19+
}
20+
}
21+
return boxes;
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.solutions.fourththousand._3074;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class _3074Test {
10+
private static _3074.Solution1 solution1;
11+
private static int[] apple;
12+
private static int[] capacity;
13+
14+
@BeforeEach
15+
public void setup() {
16+
solution1 = new _3074.Solution1();
17+
}
18+
19+
@Test
20+
public void test1() {
21+
apple = new int[]{1, 3, 2};
22+
capacity = new int[]{4, 3, 1, 5, 2};
23+
assertEquals(2, solution1.minimumBoxes(apple, capacity));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)