diff --git a/src/main/java/g0101_0200/s0178_rank_scores/script.sql b/src/main/java/g0101_0200/s0178_rank_scores/script.sql index 0e78b870b..2773cd557 100644 --- a/src/main/java/g0101_0200/s0178_rank_scores/script.sql +++ b/src/main/java/g0101_0200/s0178_rank_scores/script.sql @@ -7,4 +7,3 @@ FROM Scores ORDER BY Rank ASC; - diff --git a/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql b/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql index 4dda6cf45..0cbebed39 100644 --- a/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql +++ b/src/main/java/g0101_0200/s0182_duplicate_emails/script.sql @@ -8,4 +8,3 @@ GROUP BY Email HAVING COUNT(Email) > 1; - diff --git a/src/main/java/g3501_3600/s3558_number_of_ways_to_assign_edge_weights_i/Solution.java b/src/main/java/g3501_3600/s3558_number_of_ways_to_assign_edge_weights_i/Solution.java index 288e502dd..f06a99310 100644 --- a/src/main/java/g3501_3600/s3558_number_of_ways_to_assign_edge_weights_i/Solution.java +++ b/src/main/java/g3501_3600/s3558_number_of_ways_to_assign_edge_weights_i/Solution.java @@ -1,6 +1,6 @@ package g3501_3600.s3558_number_of_ways_to_assign_edge_weights_i; -// #Medium #Math #Tree #Depth_First_Search #2025_05_27_Time_12_ms_(100.00%)_Space_106.62_MB_(76.01%) +// #Medium #Math #Depth_First_Search #Tree #2025_05_27_Time_12_ms_(100.00%)_Space_106.62_MB_(76.01%) public class Solution { private static int mod = (int) 1e9 + 7; diff --git a/src/main/java/g3501_3600/s3559_number_of_ways_to_assign_edge_weights_ii/Solution.java b/src/main/java/g3501_3600/s3559_number_of_ways_to_assign_edge_weights_ii/Solution.java index 77d38483c..ce739a286 100644 --- a/src/main/java/g3501_3600/s3559_number_of_ways_to_assign_edge_weights_ii/Solution.java +++ b/src/main/java/g3501_3600/s3559_number_of_ways_to_assign_edge_weights_ii/Solution.java @@ -1,6 +1,6 @@ package g3501_3600.s3559_number_of_ways_to_assign_edge_weights_ii; -// #Hard #Array #Dynamic_Programming #Math #Tree #Depth_First_Search +// #Hard #Array #Dynamic_Programming #Math #Depth_First_Search #Tree // #2025_05_27_Time_138_ms_(64.66%)_Space_133.20_MB_(11.56%) import java.util.ArrayList; diff --git a/src/main/java/g3501_3600/s3562_maximum_profit_from_trading_stocks_with_discounts/Solution.java b/src/main/java/g3501_3600/s3562_maximum_profit_from_trading_stocks_with_discounts/Solution.java index c3b416e60..5d0233e4d 100644 --- a/src/main/java/g3501_3600/s3562_maximum_profit_from_trading_stocks_with_discounts/Solution.java +++ b/src/main/java/g3501_3600/s3562_maximum_profit_from_trading_stocks_with_discounts/Solution.java @@ -1,6 +1,6 @@ package g3501_3600.s3562_maximum_profit_from_trading_stocks_with_discounts; -// #Hard #Array #Dynamic_Programming #Tree #Depth_First_Search +// #Hard #Array #Dynamic_Programming #Depth_First_Search #Tree // #2025_05_27_Time_27_ms_(100.00%)_Space_45.29_MB_(82.12%) import java.util.ArrayList; diff --git a/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/Solution.java b/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/Solution.java new file mode 100644 index 000000000..4fbfbed1b --- /dev/null +++ b/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/Solution.java @@ -0,0 +1,19 @@ +package g3501_3600.s3566_partition_array_into_two_equal_product_subsets; + +// #Medium #Array #Bit_Manipulation #Recursion #Enumeration +// #2025_06_03_Time_0_ms_(100.00%)_Space_42.45_MB_(36.66%) + +public class Solution { + public boolean checkEqualPartitions(int[] nums, long target) { + for (int num : nums) { + if (target % num != 0) { + return false; + } + } + long pro = 1; + for (long n : nums) { + pro *= n; + } + return pro == target * target; + } +} diff --git a/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/readme.md b/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/readme.md new file mode 100644 index 000000000..74bdaf0d7 --- /dev/null +++ b/src/main/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/readme.md @@ -0,0 +1,34 @@ +3566\. Partition Array into Two Equal Product Subsets + +Medium + +You are given an integer array `nums` containing **distinct** positive integers and an integer `target`. + +Determine if you can partition `nums` into two **non-empty** **disjoint** **subsets**, with each element belonging to **exactly one** subset, such that the product of the elements in each subset is equal to `target`. + +Return `true` if such a partition exists and `false` otherwise. + +A **subset** of an array is a selection of elements of the array. + +**Example 1:** + +**Input:** nums = [3,1,6,8,4], target = 24 + +**Output:** true + +**Explanation:** The subsets `[3, 8]` and `[1, 6, 4]` each have a product of 24. Hence, the output is true. + +**Example 2:** + +**Input:** nums = [2,5,3,7], target = 15 + +**Output:** false + +**Explanation:** There is no way to partition `nums` into two non-empty disjoint subsets such that both subsets have a product of 15. Hence, the output is false. + +**Constraints:** + +* `3 <= nums.length <= 12` +* 1 <= target <= 1015 +* `1 <= nums[i] <= 100` +* All elements of `nums` are **distinct**. \ No newline at end of file diff --git a/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/Solution.java b/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/Solution.java new file mode 100644 index 000000000..d36439d36 --- /dev/null +++ b/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/Solution.java @@ -0,0 +1,37 @@ +package g3501_3600.s3567_minimum_absolute_difference_in_sliding_submatrix; + +// #Medium #Array #Sorting #Matrix #2025_06_03_Time_7_ms_(99.69%)_Space_45.24_MB_(99.03%) + +import java.util.Arrays; + +public class Solution { + public int[][] minAbsDiff(int[][] grid, int k) { + int rows = grid.length; + int cols = grid[0].length; + int[][] result = new int[rows - k + 1][cols - k + 1]; + for (int x = 0; x <= rows - k; x++) { + for (int y = 0; y <= cols - k; y++) { + int size = k * k; + int[] elements = new int[size]; + int idx = 0; + for (int i = x; i < x + k; i++) { + for (int j = y; j < y + k; j++) { + elements[idx++] = grid[i][j]; + } + } + Arrays.sort(elements); + int minDiff = Integer.MAX_VALUE; + for (int i = 1; i < size; i++) { + if (elements[i] != elements[i - 1]) { + minDiff = Math.min(minDiff, elements[i] - elements[i - 1]); + if (minDiff == 1) { + break; + } + } + } + result[x][y] = minDiff == Integer.MAX_VALUE ? 0 : minDiff; + } + } + return result; + } +} diff --git a/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/readme.md b/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/readme.md new file mode 100644 index 000000000..31d2e1f60 --- /dev/null +++ b/src/main/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/readme.md @@ -0,0 +1,60 @@ +3567\. Minimum Absolute Difference in Sliding Submatrix + +Medium + +You are given an `m x n` integer matrix `grid` and an integer `k`. + +For every contiguous `k x k` **submatrix** of `grid`, compute the **minimum absolute** difference between any two **distinct** values within that **submatrix**. + +Return a 2D array `ans` of size `(m - k + 1) x (n - k + 1)`, where `ans[i][j]` is the minimum absolute difference in the submatrix whose top-left corner is `(i, j)` in `grid`. + +**Note**: If all elements in the submatrix have the same value, the answer will be 0. + +A submatrix `(x1, y1, x2, y2)` is a matrix that is formed by choosing all cells `matrix[x][y]` where `x1 <= x <= x2` and `y1 <= y <= y2`. + +**Example 1:** + +**Input:** grid = [[1,8],[3,-2]], k = 2 + +**Output:** [[2]] + +**Explanation:** + +* There is only one possible `k x k` submatrix: `[[1, 8], [3, -2]]`. +* Distinct values in the submatrix are `[1, 8, 3, -2]`. +* The minimum absolute difference in the submatrix is `|1 - 3| = 2`. Thus, the answer is `[[2]]`. + +**Example 2:** + +**Input:** grid = [[3,-1]], k = 1 + +**Output:** [[0,0]] + +**Explanation:** + +* Both `k x k` submatrix has only one distinct element. +* Thus, the answer is `[[0, 0]]`. + +**Example 3:** + +**Input:** grid = [[1,-2,3],[2,3,5]], k = 2 + +**Output:** [[1,2]] + +**Explanation:** + +* There are two possible `k × k` submatrix: + * Starting at `(0, 0)`: `[[1, -2], [2, 3]]`. + * Distinct values in the submatrix are `[1, -2, 2, 3]`. + * The minimum absolute difference in the submatrix is `|1 - 2| = 1`. + * Starting at `(0, 1)`: `[[-2, 3], [3, 5]]`. + * Distinct values in the submatrix are `[-2, 3, 5]`. + * The minimum absolute difference in the submatrix is `|3 - 5| = 2`. +* Thus, the answer is `[[1, 2]]`. + +**Constraints:** + +* `1 <= m == grid.length <= 30` +* `1 <= n == grid[i].length <= 30` +* -105 <= grid[i][j] <= 105 +* `1 <= k <= min(m, n)` \ No newline at end of file diff --git a/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/Solution.java b/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/Solution.java new file mode 100644 index 000000000..2e72c83cb --- /dev/null +++ b/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/Solution.java @@ -0,0 +1,100 @@ +package g3501_3600.s3568_minimum_moves_to_clean_the_classroom; + +// #Medium #Array #Hash_Table #Breadth_First_Search #Matrix #Bit_Manipulation +// #2025_06_03_Time_94_ms_(99.86%)_Space_53.76_MB_(99.86%) + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Queue; + +@SuppressWarnings({"java:S135", "java:S6541"}) +public class Solution { + private static class State { + int x; + int y; + int energy; + int mask; + int steps; + + State(int x, int y, int energy, int mask, int steps) { + this.x = x; + this.y = y; + this.energy = energy; + this.mask = mask; + this.steps = steps; + } + } + + public int minMoves(String[] classroom, int energy) { + int m = classroom.length; + int n = classroom[0].length(); + char[][] grid = new char[m][n]; + for (int i = 0; i < m; i++) { + grid[i] = classroom[i].toCharArray(); + } + int startX = -1; + int startY = -1; + List lumetarkon = new ArrayList<>(); + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + char c = grid[i][j]; + if (c == 'S') { + startX = i; + startY = j; + } else if (c == 'L') { + lumetarkon.add(new int[] {i, j}); + } + } + } + int totalLitter = lumetarkon.size(); + int allMask = (1 << totalLitter) - 1; + int[][][] visited = new int[m][n][1 << totalLitter]; + for (int[][] layer : visited) { + for (int[] row : layer) { + Arrays.fill(row, -1); + } + } + Queue queue = new ArrayDeque<>(); + queue.offer(new State(startX, startY, energy, 0, 0)); + visited[startX][startY][0] = energy; + int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; + while (!queue.isEmpty()) { + State curr = queue.poll(); + if (curr.mask == allMask) { + return curr.steps; + } + for (int[] dir : dirs) { + int nx = curr.x + dir[0]; + int ny = curr.y + dir[1]; + if (nx < 0 || ny < 0 || nx >= m || ny >= n || grid[nx][ny] == 'X') { + continue; + } + int nextEnergy = curr.energy - 1; + if (nextEnergy < 0) { + continue; + } + char cell = grid[nx][ny]; + if (cell == 'R') { + nextEnergy = energy; + } + int nextMask = curr.mask; + if (cell == 'L') { + for (int i = 0; i < lumetarkon.size(); i++) { + int[] pos = lumetarkon.get(i); + if (pos[0] == nx && pos[1] == ny) { + nextMask |= (1 << i); + break; + } + } + } + if (visited[nx][ny][nextMask] < nextEnergy) { + visited[nx][ny][nextMask] = nextEnergy; + queue.offer(new State(nx, ny, nextEnergy, nextMask, curr.steps + 1)); + } + } + } + return -1; + } +} diff --git a/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/readme.md b/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/readme.md new file mode 100644 index 000000000..421faa12c --- /dev/null +++ b/src/main/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/readme.md @@ -0,0 +1,66 @@ +3568\. Minimum Moves to Clean the Classroom + +Medium + +You are given an `m x n` grid `classroom` where a student volunteer is tasked with cleaning up litter scattered around the room. Each cell in the grid is one of the following: + +* `'S'`: Starting position of the student +* `'L'`: Litter that must be collected (once collected, the cell becomes empty) +* `'R'`: Reset area that restores the student's energy to full capacity, regardless of their current energy level (can be used multiple times) +* `'X'`: Obstacle the student cannot pass through +* `'.'`: Empty space + +You are also given an integer `energy`, representing the student's maximum energy capacity. The student starts with this energy from the starting position `'S'`. + +Each move to an adjacent cell (up, down, left, or right) costs 1 unit of energy. If the energy reaches 0, the student can only continue if they are on a reset area `'R'`, which resets the energy to its **maximum** capacity `energy`. + +Return the **minimum** number of moves required to collect all litter items, or `-1` if it's impossible. + +**Example 1:** + +**Input:** classroom = ["S.", "XL"], energy = 2 + +**Output:** 2 + +**Explanation:** + +* The student starts at cell `(0, 0)` with 2 units of energy. +* Since cell `(1, 0)` contains an obstacle 'X', the student cannot move directly downward. +* A valid sequence of moves to collect all litter is as follows: + * Move 1: From `(0, 0)` → `(0, 1)` with 1 unit of energy and 1 unit remaining. + * Move 2: From `(0, 1)` → `(1, 1)` to collect the litter `'L'`. +* The student collects all the litter using 2 moves. Thus, the output is 2. + +**Example 2:** + +**Input:** classroom = ["LS", "RL"], energy = 4 + +**Output:** 3 + +**Explanation:** + +* The student starts at cell `(0, 1)` with 4 units of energy. +* A valid sequence of moves to collect all litter is as follows: + * Move 1: From `(0, 1)` → `(0, 0)` to collect the first litter `'L'` with 1 unit of energy used and 3 units remaining. + * Move 2: From `(0, 0)` → `(1, 0)` to `'R'` to reset and restore energy back to 4. + * Move 3: From `(1, 0)` → `(1, 1)` to collect the second litter `'L'`. +* The student collects all the litter using 3 moves. Thus, the output is 3. + +**Example 3:** + +**Input:** classroom = ["L.S", "RXL"], energy = 3 + +**Output:** \-1 + +**Explanation:** + +No valid path collects all `'L'`. + +**Constraints:** + +* `1 <= m == classroom.length <= 20` +* `1 <= n == classroom[i].length <= 20` +* `classroom[i][j]` is one of `'S'`, `'L'`, `'R'`, `'X'`, or `'.'` +* `1 <= energy <= 50` +* There is exactly **one** `'S'` in the grid. +* There are **at most** 10 `'L'` cells in the grid. \ No newline at end of file diff --git a/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/Solution.java b/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/Solution.java new file mode 100644 index 000000000..71d10c6e2 --- /dev/null +++ b/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/Solution.java @@ -0,0 +1,157 @@ +package g3501_3600.s3569_maximize_count_of_distinct_primes_after_split; + +// #Hard #Array #Math #Segment_Tree #Number_Theory +// #2025_06_03_Time_280_ms_(97.30%)_Space_76.62_MB_(52.25%) + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeSet; + +@SuppressWarnings("java:S6541") +public class Solution { + private static final int MAX_VAL = 100005; + private static boolean[] isPrime = new boolean[MAX_VAL]; + + static { + Arrays.fill(isPrime, true); + isPrime[0] = isPrime[1] = false; + for (int i = 2; i * i < MAX_VAL; i++) { + if (isPrime[i]) { + for (int j = i * i; j < MAX_VAL; j += i) { + isPrime[j] = false; + } + } + } + } + + private static class Node { + int maxVal; + int lazyDelta; + } + + private static class SegmentTree { + Node[] tree; + int n; + + public SegmentTree(int n) { + this.n = n; + tree = new Node[4 * this.n]; + for (int i = 0; i < 4 * this.n; i++) { + tree[i] = new Node(); + } + } + + private void push(int nodeIdx) { + if (tree[nodeIdx].lazyDelta != 0) { + tree[2 * nodeIdx].maxVal += tree[nodeIdx].lazyDelta; + tree[2 * nodeIdx].lazyDelta += tree[nodeIdx].lazyDelta; + tree[2 * nodeIdx + 1].maxVal += tree[nodeIdx].lazyDelta; + tree[2 * nodeIdx + 1].lazyDelta += tree[nodeIdx].lazyDelta; + tree[nodeIdx].lazyDelta = 0; + } + } + + private void update(int queryStart, int queryEnd, int delta) { + queryStart = Math.max(1, queryStart); + queryEnd = Math.min(n - 1, queryEnd); + if (queryStart > queryEnd) { + return; + } + update(1, 1, n - 1, queryStart, queryEnd, delta); + } + + private void update( + int nodeIdx, int start, int end, int queryStart, int queryEnd, int delta) { + if (start > end || start > queryEnd || end < queryStart) { + return; + } + if (queryStart <= start && end <= queryEnd) { + tree[nodeIdx].maxVal += delta; + tree[nodeIdx].lazyDelta += delta; + return; + } + push(nodeIdx); + + int mid = (start + end) / 2; + update(2 * nodeIdx, start, mid, queryStart, queryEnd, delta); + update(2 * nodeIdx + 1, mid + 1, end, queryStart, queryEnd, delta); + tree[nodeIdx].maxVal = Math.max(tree[2 * nodeIdx].maxVal, tree[2 * nodeIdx + 1].maxVal); + } + + public int queryMax() { + if (n - 1 < 1) { + return 0; + } + return tree[1].maxVal; + } + } + + public int[] maximumCount(int[] nums, int[][] queries) { + int n = nums.length; + Map> primeIndices = new HashMap<>(); + for (int i = 0; i < n; i++) { + if (isPrime[nums[i]]) { + primeIndices.computeIfAbsent(nums[i], k -> new TreeSet<>()).add(i); + } + } + SegmentTree segmentTree = new SegmentTree(n); + for (Map.Entry> entry : primeIndices.entrySet()) { + TreeSet indices = entry.getValue(); + int first = indices.first(); + int last = indices.last(); + segmentTree.update(first + 1, last, 1); + } + int[] result = new int[queries.length]; + for (int q = 0; q < queries.length; q++) { + int idx = queries[q][0]; + int val = queries[q][1]; + int oldVal = nums[idx]; + if (isPrime[oldVal]) { + TreeSet indices = primeIndices.get(oldVal); + int oldFirst = indices.first(); + int oldLast = indices.last(); + indices.remove(idx); + if (indices.isEmpty()) { + primeIndices.remove(oldVal); + segmentTree.update(oldFirst + 1, oldLast, -1); + } else { + int newFirst = indices.first(); + int newLast = indices.last(); + + if (idx == oldFirst && newFirst != oldFirst) { + segmentTree.update(oldFirst + 1, newFirst, -1); + } + if (idx == oldLast && newLast != oldLast) { + segmentTree.update(newLast + 1, oldLast, -1); + } + } + } + nums[idx] = val; + if (isPrime[val]) { + boolean wasNewPrime = !primeIndices.containsKey(val); + TreeSet indices = primeIndices.computeIfAbsent(val, k -> new TreeSet<>()); + int oldFirst = indices.isEmpty() ? -1 : indices.first(); + int oldLast = indices.isEmpty() ? -1 : indices.last(); + indices.add(idx); + int newFirst = indices.first(); + int newLast = indices.last(); + if (wasNewPrime) { + segmentTree.update(newFirst + 1, newLast, 1); + } else { + if (idx < oldFirst) { + segmentTree.update(newFirst + 1, oldFirst, 1); + } + if (idx > oldLast) { + segmentTree.update(oldLast + 1, newLast, 1); + } + } + } + int totalDistinctPrimesInCurrentNums = primeIndices.size(); + int maxIntersection = segmentTree.queryMax(); + maxIntersection = Math.max(0, maxIntersection); + result[q] = totalDistinctPrimesInCurrentNums + maxIntersection; + } + return result; + } +} diff --git a/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/readme.md b/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/readme.md new file mode 100644 index 000000000..042623001 --- /dev/null +++ b/src/main/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/readme.md @@ -0,0 +1,47 @@ +3569\. Maximize Count of Distinct Primes After Split + +Hard + +You are given an integer array `nums` having length `n` and a 2D integer array `queries` where `queries[i] = [idx, val]`. + +For each query: + +1. Update `nums[idx] = val`. +2. Choose an integer `k` with `1 <= k < n` to split the array into the non-empty prefix `nums[0..k-1]` and suffix `nums[k..n-1]` such that the sum of the counts of **distinct** prime values in each part is **maximum**. + +**Note:** The changes made to the array in one query persist into the next query. + +Return an array containing the result for each query, in the order they are given. + +**Example 1:** + +**Input:** nums = [2,1,3,1,2], queries = [[1,2],[3,3]] + +**Output:** [3,4] + +**Explanation:** + +* Initially `nums = [2, 1, 3, 1, 2]`. +* After 1st query, `nums = [2, 2, 3, 1, 2]`. Split `nums` into `[2]` and `[2, 3, 1, 2]`. `[2]` consists of 1 distinct prime and `[2, 3, 1, 2]` consists of 2 distinct primes. Hence, the answer for this query is `1 + 2 = 3`. +* After 2nd query, `nums = [2, 2, 3, 3, 2]`. Split `nums` into `[2, 2, 3]` and `[3, 2]` with an answer of `2 + 2 = 4`. +* The output is `[3, 4]`. + +**Example 2:** + +**Input:** nums = [2,1,4], queries = [[0,1]] + +**Output:** [0] + +**Explanation:** + +* Initially `nums = [2, 1, 4]`. +* After 1st query, `nums = [1, 1, 4]`. There are no prime numbers in `nums`, hence the answer for this query is 0. +* The output is `[0]`. + +**Constraints:** + +* 2 <= n == nums.length <= 5 * 104 +* 1 <= queries.length <= 5 * 104 +* 1 <= nums[i] <= 105 +* `0 <= queries[i][0] < nums.length` +* 1 <= queries[i][1] <= 105 \ No newline at end of file diff --git a/src/test/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/SolutionTest.java b/src/test/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/SolutionTest.java new file mode 100644 index 000000000..957a2f424 --- /dev/null +++ b/src/test/java/g3501_3600/s3566_partition_array_into_two_equal_product_subsets/SolutionTest.java @@ -0,0 +1,20 @@ +package g3501_3600.s3566_partition_array_into_two_equal_product_subsets; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void checkEqualPartitions() { + assertThat( + new Solution().checkEqualPartitions(new int[] {3, 1, 6, 8, 4}, 24L), equalTo(true)); + } + + @Test + void checkEqualPartitions2() { + assertThat( + new Solution().checkEqualPartitions(new int[] {2, 5, 3, 7}, 15L), equalTo(false)); + } +} diff --git a/src/test/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/SolutionTest.java b/src/test/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/SolutionTest.java new file mode 100644 index 000000000..08fdfbcce --- /dev/null +++ b/src/test/java/g3501_3600/s3567_minimum_absolute_difference_in_sliding_submatrix/SolutionTest.java @@ -0,0 +1,28 @@ +package g3501_3600.s3567_minimum_absolute_difference_in_sliding_submatrix; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minAbsDiff() { + assertThat( + new Solution().minAbsDiff(new int[][] {{1, 8}, {3, -2}}, 2), + equalTo(new int[][] {{2}})); + } + + @Test + void minAbsDiff2() { + assertThat( + new Solution().minAbsDiff(new int[][] {{3, -1}}, 1), equalTo(new int[][] {{0, 0}})); + } + + @Test + void minAbsDiff3() { + assertThat( + new Solution().minAbsDiff(new int[][] {{1, -2, 3}, {2, 3, 5}}, 2), + equalTo(new int[][] {{1, 2}})); + } +} diff --git a/src/test/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/SolutionTest.java b/src/test/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/SolutionTest.java new file mode 100644 index 000000000..42c1d9085 --- /dev/null +++ b/src/test/java/g3501_3600/s3568_minimum_moves_to_clean_the_classroom/SolutionTest.java @@ -0,0 +1,23 @@ +package g3501_3600.s3568_minimum_moves_to_clean_the_classroom; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minMoves() { + assertThat(new Solution().minMoves(new String[] {"S.", "XL"}, 2), equalTo(2)); + } + + @Test + void minMoves2() { + assertThat(new Solution().minMoves(new String[] {"LS", "RL"}, 4), equalTo(3)); + } + + @Test + void minMoves3() { + assertThat(new Solution().minMoves(new String[] {"L.S", "RXL"}, 3), equalTo(-1)); + } +} diff --git a/src/test/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/SolutionTest.java b/src/test/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/SolutionTest.java new file mode 100644 index 000000000..3f4a51693 --- /dev/null +++ b/src/test/java/g3501_3600/s3569_maximize_count_of_distinct_primes_after_split/SolutionTest.java @@ -0,0 +1,37 @@ +package g3501_3600.s3569_maximize_count_of_distinct_primes_after_split; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maximumCount() { + assertThat( + new Solution() + .maximumCount(new int[] {2, 1, 3, 1, 2}, new int[][] {{1, 2}, {3, 3}}), + equalTo(new int[] {3, 4})); + } + + @Test + void maximumCount2() { + assertThat( + new Solution().maximumCount(new int[] {2, 1, 4}, new int[][] {{0, 1}}), + equalTo(new int[] {0})); + } + + @Test + void maximumCount3() { + assertThat( + new Solution().maximumCount(new int[] {2, 34}, new int[][] {{1, 2}, {1, 3}}), + equalTo(new int[] {2, 2})); + } + + @Test + void maximumCount4() { + assertThat( + new Solution().maximumCount(new int[] {4, 2}, new int[][] {{0, 2}, {0, 2}}), + equalTo(new int[] {2, 2})); + } +}