Skip to content

Commit 13c62b7

Browse files
[LEET-3375] ADD 3375
1 parent f3e7703 commit 13c62b7

File tree

3 files changed

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

3 files changed

+53
-0
lines changed

paginated_contents/algorithms/4th_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
33
| 3396 | [Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java) | | Easy |
44
| 3392 | [Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java) | | Easy |
5+
| 3375 | [Minimum Operations to Make Array Values Equal to K](https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3375.java) | | Easy |
56
| 3370 | [Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java) | | Easy |
67
| 3364 | [Minimum Positive Sum Subarray](https://leetcode.com/problems/minimum-positive-sum-subarray/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3364.java) | | Easy |
78
| 3360 | [Stone Removal Game](https://leetcode.com/problems/stone-removal-game/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3360.java) | | Easy |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.TreeMap;
4+
5+
public class _3375 {
6+
public static class Solution1 {
7+
public int minOperations(int[] nums, int k) {
8+
TreeMap<Integer, Integer> map = new TreeMap<>();
9+
for (int num : nums) {
10+
map.put(num, map.getOrDefault(num, 0) + 1);
11+
}
12+
if (map.firstKey() < k) {
13+
return -1;
14+
}
15+
if (map.firstKey() == k) {
16+
return map.size() - 1;
17+
}
18+
return map.size();
19+
}
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.fishercoder.solutions.fourththousand._3375;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class _3375Test {
10+
private _3375.Solution1 solution1;
11+
12+
@BeforeEach
13+
public void setup() {
14+
solution1 = new _3375.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(2, solution1.minOperations(new int[] {5, 2, 5, 4, 5}, 2));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(-1, solution1.minOperations(new int[] {2, 1, 2}, 2));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(4, solution1.minOperations(new int[] {9, 7, 5, 3}, 1));
30+
}
31+
}

0 commit comments

Comments
 (0)