diff --git a/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/Solution.java b/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/Solution.java new file mode 100644 index 000000000..f62bf14f0 --- /dev/null +++ b/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/Solution.java @@ -0,0 +1,24 @@ +package g3001_3100.s3070_count_submatrices_with_top_left_element_and_sum_less_than_k; + +// #Medium #Array #Matrix #Prefix_Sum #2024_04_15_Time_2_ms_(100.00%)_Space_117.3_MB_(94.08%) + +public class Solution { + public int countSubmatrices(int[][] grid, int k) { + int n = grid[0].length; + int[] sums = new int[n]; + int ans = 0; + for (int[] ints : grid) { + int sum = 0; + for (int col = 0; col < n; col++) { + sum += ints[col]; + sums[col] += sum; + if (sums[col] <= k) { + ans++; + } else { + break; + } + } + } + return ans; + } +} diff --git a/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/readme.md b/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/readme.md new file mode 100644 index 000000000..760f1f3a3 --- /dev/null +++ b/src/main/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/readme.md @@ -0,0 +1,35 @@ +3070\. Count Submatrices with Top-Left Element and Sum Less Than k + +Medium + +You are given a **0-indexed** integer matrix `grid` and an integer `k`. + +Return _the **number** of submatrices that contain the top-left element of the_ `grid`, _and have a sum less than or equal to_ `k`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2024/01/01/example1.png) + +**Input:** grid = [[7,6,3],[6,6,1]], k = 18 + +**Output:** 4 + +**Explanation:** There are only 4 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 18. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2024/01/01/example21.png) + +**Input:** grid = [[7,2,9],[1,5,0],[2,6,6]], k = 20 + +**Output:** 6 + +**Explanation:** There are only 6 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 20. + +**Constraints:** + +* `m == grid.length` +* `n == grid[i].length` +* `1 <= n, m <= 1000` +* `0 <= grid[i][j] <= 1000` +* 1 <= k <= 109 \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/Solution.java b/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/Solution.java new file mode 100644 index 000000000..5c8391448 --- /dev/null +++ b/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/Solution.java @@ -0,0 +1,47 @@ +package g3001_3100.s3071_minimum_operations_to_write_the_letter_y_on_a_grid; + +// #Medium #Array #Hash_Table #Matrix #Counting #2024_04_15_Time_1_ms_(100.00%)_Space_45_MB_(60.73%) + +public class Solution { + public int minimumOperationsToWriteY(int[][] arr) { + int n = arr.length; + int[] cnt1 = new int[3]; + int[] cnt2 = new int[3]; + int x = n / 2; + int y = n / 2; + for (int j = x; j < n; j++) { + cnt1[arr[j][y]]++; + arr[j][y] = 3; + } + for (int j = x; j >= 0; j--) { + if (arr[j][j] != 3) { + cnt1[arr[j][j]]++; + } + arr[j][j] = 3; + } + for (int j = x; j >= 0; j--) { + if (arr[j][n - 1 - j] != 3) { + cnt1[arr[j][n - 1 - j]]++; + } + arr[j][n - 1 - j] = 3; + } + for (int[] ints : arr) { + for (int j = 0; j < n; j++) { + if (ints[j] != 3) { + cnt2[ints[j]]++; + } + } + } + int s1 = cnt1[0] + cnt1[1] + cnt1[2]; + int s2 = cnt2[0] + cnt2[1] + cnt2[2]; + int min = Integer.MAX_VALUE; + for (int i = 0; i <= 2; i++) { + for (int j = 0; j <= 2; j++) { + if (i != j) { + min = Math.min(s1 - cnt1[i] + s2 - cnt2[j], min); + } + } + } + return min; + } +} diff --git a/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/readme.md b/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/readme.md new file mode 100644 index 000000000..a3efc92b0 --- /dev/null +++ b/src/main/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/readme.md @@ -0,0 +1,46 @@ +3071\. Minimum Operations to Write the Letter Y on a Grid + +Medium + +You are given a **0-indexed** `n x n` grid where `n` is odd, and `grid[r][c]` is `0`, `1`, or `2`. + +We say that a cell belongs to the Letter **Y** if it belongs to one of the following: + +* The diagonal starting at the top-left cell and ending at the center cell of the grid. +* The diagonal starting at the top-right cell and ending at the center cell of the grid. +* The vertical line starting at the center cell and ending at the bottom border of the grid. + +The Letter **Y** is written on the grid if and only if: + +* All values at cells belonging to the Y are equal. +* All values at cells not belonging to the Y are equal. +* The values at cells belonging to the Y are different from the values at cells not belonging to the Y. + +Return _the **minimum** number of operations needed to write the letter Y on the grid given that in one operation you can change the value at any cell to_ `0`_,_ `1`_,_ _or_ `2`_._ + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2024/01/22/y2.png) + +**Input:** grid = [[1,2,2],[1,1,0],[0,1,0]] + +**Output:** 3 + +**Explanation:** We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 1 while those that do not belong to Y are equal to 0. It can be shown that 3 is the minimum number of operations needed to write Y on the grid. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2024/01/22/y3.png) + +**Input:** grid = [[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]] + +**Output:** 12 + +**Explanation:** We can write Y on the grid by applying the changes highlighted in blue in the image above. After the operations, all cells that belong to Y, denoted in bold, have the same value of 0 while those that do not belong to Y are equal to 2. It can be shown that 12 is the minimum number of operations needed to write Y on the grid. + +**Constraints:** + +* `3 <= n <= 49` +* `n == grid.length == grid[i].length` +* `0 <= grid[i][j] <= 2` +* `n` is odd. \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/Solution.java b/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/Solution.java new file mode 100644 index 000000000..d3de0f349 --- /dev/null +++ b/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/Solution.java @@ -0,0 +1,88 @@ +package g3001_3100.s3072_distribute_elements_into_two_arrays_ii; + +// #Hard #Array #Simulation #Segment_Tree #Binary_Indexed_Tree +// #2024_04_15_Time_48_ms_(99.90%)_Space_65_MB_(74.73%) + +import java.util.Arrays; + +public class Solution { + static class BIT { + private final int[] tree; + + public BIT(int size) { + tree = new int[size + 1]; + } + + public void update(int ind) { + while (ind < tree.length) { + tree[ind]++; + ind += lsb(ind); + } + } + + public int rsq(int ind) { + int sum = 0; + while (ind > 0) { + sum += tree[ind]; + ind -= lsb(ind); + } + + return sum; + } + + private int lsb(int n) { + return n & (-n); + } + } + + public int[] resultArray(int[] source) { + int[] nums = shrink(source); + int[] arr1 = new int[nums.length]; + int[] arr2 = new int[nums.length]; + arr1[0] = source[0]; + arr2[0] = source[1]; + int p1 = 0; + int p2 = 0; + BIT bit1 = new BIT(nums.length); + bit1.update(nums[0]); + BIT bit2 = new BIT(nums.length); + bit2.update(nums[1]); + + for (int i = 2; i < nums.length; i++) { + int g1 = p1 + 1 - bit1.rsq(nums[i]); + int g2 = p2 + 1 - bit2.rsq(nums[i]); + if (g1 < g2 || p1 > p2) { + p2++; + arr2[p2] = source[i]; + bit2.update(nums[i]); + } else { + p1++; + arr1[p1] = source[i]; + bit1.update(nums[i]); + } + } + + for (int i = p1 + 1; i < arr1.length; i++) { + arr1[i] = arr2[i - p1 - 1]; + } + + return arr1; + } + + private int[] shrink(int[] nums) { + long[] b = new long[nums.length]; + for (int i = 0; i < nums.length; i++) { + b[i] = (long) nums[i] << 32 | i; + } + Arrays.sort(b); + int[] result = new int[nums.length]; + int p = 1; + for (int i = 0; i < nums.length; i++) { + if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) { + p++; + } + result[(int) b[i]] = p; + } + return result; + } +} diff --git a/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/readme.md b/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/readme.md new file mode 100644 index 000000000..dbb65039c --- /dev/null +++ b/src/main/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/readme.md @@ -0,0 +1,59 @@ +3072\. Distribute Elements Into Two Arrays II + +Hard + +You are given a **1-indexed** array of integers `nums` of length `n`. + +We define a function `greaterCount` such that `greaterCount(arr, val)` returns the number of elements in `arr` that are **strictly greater** than `val`. + +You need to distribute all the elements of `nums` between two arrays `arr1` and `arr2` using `n` operations. In the first operation, append `nums[1]` to `arr1`. In the second operation, append `nums[2]` to `arr2`. Afterwards, in the ith operation: + +* If `greaterCount(arr1, nums[i]) > greaterCount(arr2, nums[i])`, append `nums[i]` to `arr1`. +* If `greaterCount(arr1, nums[i]) < greaterCount(arr2, nums[i])`, append `nums[i]` to `arr2`. +* If `greaterCount(arr1, nums[i]) == greaterCount(arr2, nums[i])`, append `nums[i]` to the array with a **lesser** number of elements. +* If there is still a tie, append `nums[i]` to `arr1`. + +The array `result` is formed by concatenating the arrays `arr1` and `arr2`. For example, if `arr1 == [1,2,3]` and `arr2 == [4,5,6]`, then `result = [1,2,3,4,5,6]`. + +Return _the integer array_ `result`. + +**Example 1:** + +**Input:** nums = [2,1,3,3] + +**Output:** [2,3,1,3] + +**Explanation:** After the first 2 operations, arr1 = [2] and arr2 = [1]. + +In the 3rd operation, the number of elements greater than 3 is zero in both arrays. + +Also, the lengths are equal, hence, append nums[3] to arr1. In the 4th operation, the number of elements greater than 3 is zero in both arrays. As the length of arr2 is lesser, hence, append nums[4] to arr2. + +After 4 operations, arr1 = [2,3] and arr2 = [1,3]. Hence, the array result formed by concatenation is [2,3,1,3]. + +**Example 2:** + +**Input:** nums = [5,14,3,1,2] + +**Output:** [5,3,1,2,14] + +**Explanation:** After the first 2 operations, arr1 = [5] and arr2 = [14]. + +In the 3rd operation, the number of elements greater than 3 is one in both arrays. Also, the lengths are equal, hence, append nums[3] to arr1. + +In the 4th operation, the number of elements greater than 1 is greater in arr1 than arr2 (2 > 1). Hence, append nums[4] to arr1. In the 5th operation, the number of elements greater than 2 is greater in arr1 than arr2 (2 > 1). Hence, append nums[5] to arr1. + +zAfter 5 operations, arr1 = [5,3,1,2] and arr2 = [14]. Hence, the array result formed by concatenation is [5,3,1,2,14]. + +**Example 3:** + +**Input:** nums = [3,3,3,3] + +**Output:** [3,3,3,3] + +**Explanation:** At the end of 4 operations, arr1 = [3,3] and arr2 = [3,3]. Hence, the array result formed by concatenation is [3,3,3,3]. + +**Constraints:** + +* 3 <= n <= 105 +* 1 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.java b/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.java new file mode 100644 index 000000000..1543873b1 --- /dev/null +++ b/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.java @@ -0,0 +1,32 @@ +package g3001_3100.s3074_apple_redistribution_into_boxes; + +// #Easy #Array #Sorting #Greedy #2024_04_15_Time_1_ms_(99.81%)_Space_41.9_MB_(89.46%) + +public class Solution { + public int minimumBoxes(int[] apple, int[] capacity) { + int[] count = new int[51]; + int appleSum = 0; + for (int j : apple) { + appleSum += j; + } + int reqCapacity = 0; + int max = 0; + for (int j : capacity) { + count[j]++; + max = Math.max(max, j); + } + for (int i = max; i >= 0; i--) { + if (count[i] >= 1) { + while (count[i] != 0) { + appleSum -= i; + reqCapacity++; + if (appleSum <= 0) { + return reqCapacity; + } + count[i]--; + } + } + } + return reqCapacity; + } +} diff --git a/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/readme.md b/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/readme.md new file mode 100644 index 000000000..a79cb4d2c --- /dev/null +++ b/src/main/java/g3001_3100/s3074_apple_redistribution_into_boxes/readme.md @@ -0,0 +1,34 @@ +3074\. Apple Redistribution into Boxes + +Easy + +You are given an array `apple` of size `n` and an array `capacity` of size `m`. + +There are `n` packs where the ith pack contains `apple[i]` apples. There are `m` boxes as well, and the ith box has a capacity of `capacity[i]` apples. + +Return _the **minimum** number of boxes you need to select to redistribute these_ `n` _packs of apples into boxes_. + +**Note** that, apples from the same pack can be distributed into different boxes. + +**Example 1:** + +**Input:** apple = [1,3,2], capacity = [4,3,1,5,2] + +**Output:** 2 + +**Explanation:** We will use boxes with capacities 4 and 5. It is possible to distribute the apples as the total capacity is greater than or equal to the total number of apples. + +**Example 2:** + +**Input:** apple = [5,5,5], capacity = [2,4,2,7] + +**Output:** 4 + +**Explanation:** We will need to use all the boxes. + +**Constraints:** + +* `1 <= n == apple.length <= 50` +* `1 <= m == capacity.length <= 50` +* `1 <= apple[i], capacity[i] <= 50` +* The input is generated such that it's possible to redistribute packs of apples into boxes. \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/Solution.java b/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/Solution.java new file mode 100644 index 000000000..b803741cf --- /dev/null +++ b/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/Solution.java @@ -0,0 +1,17 @@ +package g3001_3100.s3075_maximize_happiness_of_selected_children; + +// #Medium #Array #Sorting #Greedy #2024_04_15_Time_34_ms_(97.43%)_Space_61.4_MB_(77.84%) + +import java.util.Arrays; + +public class Solution { + public long maximumHappinessSum(int[] happiness, int k) { + Arrays.sort(happiness); + long sum = 0; + for (int i = happiness.length - 1; i >= happiness.length - k; i--) { + happiness[i] = Math.max(0, happiness[i] - (happiness.length - 1 - i)); + sum += happiness[i]; + } + return sum; + } +} diff --git a/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/readme.md b/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/readme.md new file mode 100644 index 000000000..2826c4644 --- /dev/null +++ b/src/main/java/g3001_3100/s3075_maximize_happiness_of_selected_children/readme.md @@ -0,0 +1,52 @@ +3075\. Maximize Happiness of Selected Children + +Medium + +You are given an array `happiness` of length `n`, and a **positive** integer `k`. + +There are `n` children standing in a queue, where the ith child has **happiness value** `happiness[i]`. You want to select `k` children from these `n` children in `k` turns. + +In each turn, when you select a child, the **happiness value** of all the children that have **not** been selected till now decreases by `1`. Note that the happiness value **cannot** become negative and gets decremented **only** if it is positive. + +Return _the **maximum** sum of the happiness values of the selected children you can achieve by selecting_ `k` _children_. + +**Example 1:** + +**Input:** happiness = [1,2,3], k = 2 + +**Output:** 4 + +**Explanation:** We can pick 2 children in the following way: +- Pick the child with the happiness value == 3. The happiness value of the remaining children becomes [0,1]. +- Pick the child with the happiness value == 1. The happiness value of the remaining child becomes [0]. Note that the happiness value cannot become less than 0. + +The sum of the happiness values of the selected children is 3 + 1 = 4. + +**Example 2:** + +**Input:** happiness = [1,1,1,1], k = 2 + +**Output:** 1 + +**Explanation:** We can pick 2 children in the following way: +- Pick any child with the happiness value == 1. The happiness value of the remaining children becomes [0,0,0]. +- Pick the child with the happiness value == 0. The happiness value of the remaining child becomes [0,0]. + +The sum of the happiness values of the selected children is 1 + 0 = 1. + +**Example 3:** + +**Input:** happiness = [2,3,4,5], k = 1 + +**Output:** 5 + +**Explanation:** We can pick 1 child in the following way: +- Pick the child with the happiness value == 5. The happiness value of the remaining children becomes [1,2,3]. + +The sum of the happiness values of the selected children is 5. + +**Constraints:** + +* 1 <= n == happiness.length <= 2 * 105 +* 1 <= happiness[i] <= 108 +* `1 <= k <= n` \ No newline at end of file diff --git a/src/test/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/SolutionTest.java b/src/test/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/SolutionTest.java new file mode 100644 index 000000000..f5f5d6387 --- /dev/null +++ b/src/test/java/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k/SolutionTest.java @@ -0,0 +1,33 @@ +package g3001_3100.s3070_count_submatrices_with_top_left_element_and_sum_less_than_k; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import com_github_leetcode.CommonUtils; +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void countSubmatrices() { + assertThat( + new Solution() + .countSubmatrices( + CommonUtils + .convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[7,6,3],[6,6,1]"), + 18), + equalTo(4)); + } + + @Test + void countSubmatrices2() { + assertThat( + new Solution() + .countSubmatrices( + CommonUtils + .convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[7,2,9],[1,5,0],[2,6,6]"), + 20), + equalTo(6)); + } +} diff --git a/src/test/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/SolutionTest.java b/src/test/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/SolutionTest.java new file mode 100644 index 000000000..8cc551e08 --- /dev/null +++ b/src/test/java/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid/SolutionTest.java @@ -0,0 +1,31 @@ +package g3001_3100.s3071_minimum_operations_to_write_the_letter_y_on_a_grid; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import com_github_leetcode.CommonUtils; +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minimumOperationsToWriteY() { + assertThat( + new Solution() + .minimumOperationsToWriteY( + CommonUtils + .convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[1,2,2],[1,1,0],[0,1,0]")), + equalTo(3)); + } + + @Test + void minimumOperationsToWriteY2() { + assertThat( + new Solution() + .minimumOperationsToWriteY( + CommonUtils + .convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[0,1,0,1,0],[2,1,0,1,2],[2,2,2,0,1],[2,2,2,2,2],[2,1,2,2,2]")), + equalTo(12)); + } +} diff --git a/src/test/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/SolutionTest.java b/src/test/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/SolutionTest.java new file mode 100644 index 000000000..756ad0c89 --- /dev/null +++ b/src/test/java/g3001_3100/s3072_distribute_elements_into_two_arrays_ii/SolutionTest.java @@ -0,0 +1,29 @@ +package g3001_3100.s3072_distribute_elements_into_two_arrays_ii; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void resultArray() { + assertThat( + new Solution().resultArray(new int[] {2, 1, 3, 3}), + equalTo(new int[] {2, 3, 1, 3})); + } + + @Test + void resultArray2() { + assertThat( + new Solution().resultArray(new int[] {5, 14, 3, 1, 2}), + equalTo(new int[] {5, 3, 2, 14, 1})); + } + + @Test + void resultArray3() { + assertThat( + new Solution().resultArray(new int[] {3, 3, 3, 3}), + equalTo(new int[] {3, 3, 3, 3})); + } +} diff --git a/src/test/java/g3001_3100/s3074_apple_redistribution_into_boxes/SolutionTest.java b/src/test/java/g3001_3100/s3074_apple_redistribution_into_boxes/SolutionTest.java new file mode 100644 index 000000000..876fc9b52 --- /dev/null +++ b/src/test/java/g3001_3100/s3074_apple_redistribution_into_boxes/SolutionTest.java @@ -0,0 +1,22 @@ +package g3001_3100.s3074_apple_redistribution_into_boxes; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minimumBoxes() { + assertThat( + new Solution().minimumBoxes(new int[] {1, 3, 2}, new int[] {4, 3, 1, 5, 2}), + equalTo(2)); + } + + @Test + void minimumBoxes2() { + assertThat( + new Solution().minimumBoxes(new int[] {5, 5, 5}, new int[] {2, 4, 2, 7}), + equalTo(4)); + } +} diff --git a/src/test/java/g3001_3100/s3075_maximize_happiness_of_selected_children/SolutionTest.java b/src/test/java/g3001_3100/s3075_maximize_happiness_of_selected_children/SolutionTest.java new file mode 100644 index 000000000..8652db724 --- /dev/null +++ b/src/test/java/g3001_3100/s3075_maximize_happiness_of_selected_children/SolutionTest.java @@ -0,0 +1,23 @@ +package g3001_3100.s3075_maximize_happiness_of_selected_children; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maximumHappinessSum() { + assertThat(new Solution().maximumHappinessSum(new int[] {1, 2, 3}, 2), equalTo(4L)); + } + + @Test + void maximumHappinessSum2() { + assertThat(new Solution().maximumHappinessSum(new int[] {1, 1, 1, 1}, 2), equalTo(1L)); + } + + @Test + void maximumHappinessSum3() { + assertThat(new Solution().maximumHappinessSum(new int[] {2, 3, 4, 5}, 1), equalTo(5L)); + } +}