diff --git a/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/Solution.kt b/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/Solution.kt new file mode 100644 index 000000000..7fd190b87 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/Solution.kt @@ -0,0 +1,18 @@ +package g3401_3500.s3423_maximum_difference_between_adjacent_elements_in_a_circular_array + +// #Easy #2025_01_19_Time_2_(100.00%)_Space_38.80_(100.00%) + +import kotlin.math.abs +import kotlin.math.max + +class Solution { + fun maxAdjacentDistance(nums: IntArray): Int { + var maxDiff = 0 + for (i in nums.indices) { + val nextIndex = (i + 1) % nums.size + val diff = abs((nums[i] - nums[nextIndex])) + maxDiff = max(maxDiff, diff) + } + return maxDiff + } +} diff --git a/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/readme.md b/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/readme.md new file mode 100644 index 000000000..924b26986 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/readme.md @@ -0,0 +1,32 @@ +3423\. Maximum Difference Between Adjacent Elements in a Circular Array + +Easy + +Given a **circular** array `nums`, find the **maximum** absolute difference between adjacent elements. + +**Note**: In a circular array, the first and last elements are adjacent. + +**Example 1:** + +**Input:** nums = [1,2,4] + +**Output:** 3 + +**Explanation:** + +Because `nums` is circular, `nums[0]` and `nums[2]` are adjacent. They have the maximum absolute difference of `|4 - 1| = 3`. + +**Example 2:** + +**Input:** nums = [-5,-10,-5] + +**Output:** 5 + +**Explanation:** + +The adjacent elements `nums[0]` and `nums[1]` have the maximum absolute difference of `|-5 - (-10)| = 5`. + +**Constraints:** + +* `2 <= nums.length <= 100` +* `-100 <= nums[i] <= 100` \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/Solution.kt b/src/main/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/Solution.kt new file mode 100644 index 000000000..6921be99c --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/Solution.kt @@ -0,0 +1,28 @@ +package g3401_3500.s3424_minimum_cost_to_make_arrays_identical + +// #Medium #Array #Sorting #Greedy #2025_01_23_Time_38_(100.00%)_Space_64.36_(97.14%) + +import kotlin.math.abs +import kotlin.math.min + +class Solution { + fun minCost(arr: IntArray, brr: IntArray, k: Long): Long { + val n = arr.size + var sum1: Long = 0 + var sum2: Long + for (i in 0..1 <= arr.length == brr.length <= 105 +* 0 <= k <= 2 * 1010 +* -105 <= arr[i] <= 105 +* -105 <= brr[i] <= 105 \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3425_longest_special_path/Solution.kt b/src/main/kotlin/g3401_3500/s3425_longest_special_path/Solution.kt new file mode 100644 index 000000000..7930edcc8 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3425_longest_special_path/Solution.kt @@ -0,0 +1,91 @@ +package g3401_3500.s3425_longest_special_path + +// #Hard #2025_01_19_Time_106_(100.00%)_Space_187.68_(100.00%) + +class Solution { + private lateinit var adj: Array> + private lateinit var nums: IntArray + private lateinit var dist: IntArray + private lateinit var lastOccur: IntArray + private lateinit var pathStack: ArrayList + private var minIndex = 0 + private var maxLen = 0 + private var minNodesForMaxLen = 0 + + fun longestSpecialPath(edges: Array, nums: IntArray): IntArray { + val n = nums.size + this.nums = nums + adj = Array>(n) { ArrayList() } + for (i in 0..() + } + for (e in edges) { + val u = e[0] + val v = e[1] + val w = e[2] + adj[u].add(intArrayOf(v, w)) + adj[v].add(intArrayOf(u, w)) + } + dist = IntArray(n) + buildDist(0, -1, 0) + var maxVal = 0 + for (`val` in nums) { + if (`val` > maxVal) { + maxVal = `val` + } + } + lastOccur = IntArray(maxVal + 1) + lastOccur.fill(-1) + pathStack = ArrayList() + minIndex = 0 + maxLen = 0 + minNodesForMaxLen = Int.Companion.MAX_VALUE + dfs(0, -1) + return intArrayOf(maxLen, minNodesForMaxLen) + } + + private fun buildDist(u: Int, parent: Int, currDist: Int) { + dist[u] = currDist + for (edge in adj[u]) { + val v = edge[0] + val w = edge[1] + if (v == parent) { + continue + } + buildDist(v, u, currDist + w) + } + } + + private fun dfs(u: Int, parent: Int) { + val stackPos = pathStack.size + pathStack.add(u) + val `val` = nums[u] + val oldPos = lastOccur[`val`] + val oldMinIndex = minIndex + lastOccur[`val`] = stackPos + if (oldPos >= minIndex) { + minIndex = oldPos + 1 + } + if (minIndex <= stackPos) { + val ancestor = pathStack[minIndex] + val pathLength = dist[u] - dist[ancestor] + val pathNodes = stackPos - minIndex + 1 + if (pathLength > maxLen) { + maxLen = pathLength + minNodesForMaxLen = pathNodes + } else if (pathLength == maxLen && pathNodes < minNodesForMaxLen) { + minNodesForMaxLen = pathNodes + } + } + for (edge in adj[u]) { + val v = edge[0] + if (v == parent) { + continue + } + dfs(v, u) + } + pathStack.removeAt(pathStack.size - 1) + lastOccur[`val`] = oldPos + minIndex = oldMinIndex + } +} diff --git a/src/main/kotlin/g3401_3500/s3425_longest_special_path/readme.md b/src/main/kotlin/g3401_3500/s3425_longest_special_path/readme.md new file mode 100644 index 000000000..53b174799 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3425_longest_special_path/readme.md @@ -0,0 +1,48 @@ +3425\. Longest Special Path + +Hard + +You are given an undirected tree rooted at node `0` with `n` nodes numbered from `0` to `n - 1`, represented by a 2D array `edges` of length `n - 1`, where edges[i] = [ui, vi, lengthi] indicates an edge between nodes ui and vi with length lengthi. You are also given an integer array `nums`, where `nums[i]` represents the value at node `i`. + +A **special path** is defined as a **downward** path from an ancestor node to a descendant node such that all the values of the nodes in that path are **unique**. + +**Note** that a path may start and end at the same node. + +Return an array `result` of size 2, where `result[0]` is the **length** of the **longest** special path, and `result[1]` is the **minimum** number of nodes in all _possible_ **longest** special paths. + +**Example 1:** + +**Input:** edges = [[0,1,2],[1,2,3],[1,3,5],[1,4,4],[2,5,6]], nums = [2,1,2,1,3,1] + +**Output:** [6,2] + +**Explanation:** + +#### In the image below, nodes are colored by their corresponding values in `nums` + +![](https://assets.leetcode.com/uploads/2024/11/02/tree3.jpeg) + +The longest special paths are `2 -> 5` and `0 -> 1 -> 4`, both having a length of 6. The minimum number of nodes across all longest special paths is 2. + +**Example 2:** + +**Input:** edges = [[1,0,8]], nums = [2,2] + +**Output:** [0,1] + +**Explanation:** + +![](https://assets.leetcode.com/uploads/2024/11/02/tree4.jpeg) + +The longest special paths are `0` and `1`, both having a length of 0. The minimum number of nodes across all longest special paths is 1. + +**Constraints:** + +* 2 <= n <= 5 * 104 +* `edges.length == n - 1` +* `edges[i].length == 3` +* 0 <= ui, vi < n +* 1 <= lengthi <= 103 +* `nums.length == n` +* 0 <= nums[i] <= 5 * 104 +* The input is generated such that `edges` represents a valid tree. \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/Solution.kt b/src/main/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/Solution.kt new file mode 100644 index 000000000..3d2044eb5 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/Solution.kt @@ -0,0 +1,40 @@ +package g3401_3500.s3426_manhattan_distances_of_all_arrangements_of_pieces + +// #Hard #2025_01_19_Time_21_(100.00%)_Space_34.61_(100.00%) + +class Solution { + private fun comb(a: Long, b: Long, mod: Long): Long { + if (b > a) { + return 0 + } + var numer: Long = 1 + var denom: Long = 1 + for (i in 0.. 0) { + if (exp % 2 > 0) { + denomInv = denomInv * denom % mod + } + denom = denom * denom % mod + exp /= 2 + } + return numer * denomInv % mod + } + + fun distanceSum(m: Int, n: Int, k: Int): Int { + var res: Long = 0 + val mod: Long = 1000000007 + val base = comb(m.toLong() * n - 2, k - 2L, mod) + for (d in 1..109 + 7. + +The Manhattan Distance between two cells (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|. + +**Example 1:** + +**Input:** m = 2, n = 2, k = 2 + +**Output:** 8 + +**Explanation:** + +The valid arrangements of pieces on the board are: + +![](https://assets.leetcode.com/uploads/2024/12/25/4040example1.drawio)![](https://assets.leetcode.com/uploads/2024/12/25/untitled-diagramdrawio.png) + +* In the first 4 arrangements, the Manhattan distance between the two pieces is 1. +* In the last 2 arrangements, the Manhattan distance between the two pieces is 2. + +Thus, the total Manhattan distance across all valid arrangements is `1 + 1 + 1 + 1 + 2 + 2 = 8`. + +**Example 2:** + +**Input:** m = 1, n = 4, k = 3 + +**Output:** 20 + +**Explanation:** + +The valid arrangements of pieces on the board are: + +![](https://assets.leetcode.com/uploads/2024/12/25/4040example2drawio.png) + +* The first and last arrangements have a total Manhattan distance of `1 + 1 + 2 = 4`. +* The middle two arrangements have a total Manhattan distance of `1 + 2 + 3 = 6`. + +The total Manhattan distance between all pairs of pieces across all arrangements is `4 + 6 + 6 + 4 = 20`. + +**Constraints:** + +* 1 <= m, n <= 105 +* 2 <= m * n <= 105 +* `2 <= k <= m * n` \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/Solution.kt b/src/main/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/Solution.kt new file mode 100644 index 000000000..408438da4 --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/Solution.kt @@ -0,0 +1,15 @@ +package g3401_3500.s3427_sum_of_variable_length_subarrays + +// #Easy #Array #Prefix_Sum #2025_01_22_Time_0_(100.00%)_Space_43.77_(58.41%) + +class Solution { + fun subarraySum(nums: IntArray): Int { + var res = nums[0] + for (i in 1.. 0) { + if ((b and 1L) == 1L) `val` = (`val` * a) % m + b = b shr 1 + a = (a * a) % m + } + return `val` + } + + private fun nCr(n: Int, r: Int): Long { + if (r < 0 || r > n) return 0 + return (fact[n] * inv[r] % MOD * inv[n - r]) % MOD + } + + fun minMaxSums(nums: IntArray, k: Int): Int { + val n = nums.size + nums.sort() + precomputeFactorials(n) + var sum: Long = 0 + for (i in 0..109 + 7. + +**Example 1:** + +**Input:** nums = [1,2,3], k = 2 + +**Output:** 24 + +**Explanation:** + +The subsequences of `nums` with at most 2 elements are: + +| **Subsequence** | Minimum | Maximum | Sum | +|-----------------|---------|---------|------| +| `[1]` | 1 | 1 | 2 | +| `[2]` | 2 | 2 | 4 | +| `[3]` | 3 | 3 | 6 | +| `[1, 2]` | 1 | 2 | 3 | +| `[1, 3]` | 1 | 3 | 4 | +| `[2, 3]` | 2 | 3 | 5 | +| **Final Total** | | | 24 | + +The output would be 24. + +**Example 2:** + +**Input:** nums = [5,0,6], k = 1 + +**Output:** 22 + +**Explanation:** + +For subsequences with exactly 1 element, the minimum and maximum values are the element itself. Therefore, the total is `5 + 5 + 0 + 0 + 6 + 6 = 22`. + +**Example 3:** + +**Input:** nums = [1,1,1], k = 2 + +**Output:** 12 + +**Explanation:** + +The subsequences `[1, 1]` and `[1]` each appear 3 times. For all of them, the minimum and maximum are both 1. Thus, the total is 12. + +**Constraints:** + +* 1 <= nums.length <= 105 +* 0 <= nums[i] <= 109 +* `1 <= k <= min(70, nums.length)` \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3429_paint_house_iv/Solution.kt b/src/main/kotlin/g3401_3500/s3429_paint_house_iv/Solution.kt new file mode 100644 index 000000000..3ea8d3d5e --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3429_paint_house_iv/Solution.kt @@ -0,0 +1,41 @@ +package g3401_3500.s3429_paint_house_iv + +// #Medium #Array #Dynamic_Programming #2025_01_22_Time_10_(100.00%)_Space_119.77_(84.62%) + +import kotlin.math.min + +class Solution { + fun minCost(n: Int, cost: Array): Long { + var dp0: Long = 0 + var dp1: Long = 0 + var dp2: Long = 0 + var dp3: Long = 0 + var dp4: Long = 0 + var dp5: Long = 0 + for (i in 0..2 <= n <= 105 +* `n` is even. +* `cost.length == n` +* `cost[i].length == 3` +* 0 <= cost[i]\[j] <= 105 \ No newline at end of file diff --git a/src/main/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/Solution.kt b/src/main/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/Solution.kt new file mode 100644 index 000000000..0bbb76e1e --- /dev/null +++ b/src/main/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/Solution.kt @@ -0,0 +1,47 @@ +package g3401_3500.s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays + +// #Hard #Array #Math #Stack #Monotonic_Stack #2025_01_22_Time_31_(100.00%)_Space_74.84_(24.24%) + +import kotlin.math.min + +class Solution { + fun minMaxSubarraySum(nums: IntArray, k: Int): Long { + val sum = solve(nums, k) + for (i in nums.indices) { + nums[i] = -nums[i] + } + return sum - solve(nums, k) + } + + private fun solve(nums: IntArray, k: Int): Long { + val n = nums.size + val left = IntArray(n) + val right = IntArray(n) + val st = IntArray(n) + var top = -1 + for (i in 0..-106 <= nums[i] <= 106 \ No newline at end of file diff --git a/src/test/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/SolutionTest.kt new file mode 100644 index 000000000..22cf8d1da --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3423_maximum_difference_between_adjacent_elements_in_a_circular_array/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3401_3500.s3423_maximum_difference_between_adjacent_elements_in_a_circular_array + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun maxAdjacentDistance() { + assertThat( + Solution().maxAdjacentDistance(intArrayOf(1, 2, 4)), + equalTo(3), + ) + } + + @Test + fun maxAdjacentDistance2() { + assertThat( + Solution().maxAdjacentDistance(intArrayOf(-5, -10, -5)), + equalTo(5), + ) + } +} diff --git a/src/test/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/SolutionTest.kt new file mode 100644 index 000000000..d04b95eb0 --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3424_minimum_cost_to_make_arrays_identical/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3401_3500.s3424_minimum_cost_to_make_arrays_identical + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minCost() { + assertThat( + Solution().minCost(intArrayOf(-7, 9, 5), intArrayOf(7, -2, -5), 2), + equalTo(13L), + ) + } + + @Test + fun minCost2() { + assertThat( + Solution().minCost(intArrayOf(2, 1), intArrayOf(2, 1), 0), + equalTo(0L), + ) + } +} diff --git a/src/test/kotlin/g3401_3500/s3425_longest_special_path/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3425_longest_special_path/SolutionTest.kt new file mode 100644 index 000000000..510154170 --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3425_longest_special_path/SolutionTest.kt @@ -0,0 +1,33 @@ +package g3401_3500.s3425_longest_special_path + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun longestSpecialPath() { + assertThat( + Solution() + .longestSpecialPath( + arrayOf( + intArrayOf(0, 1, 2), + intArrayOf(1, 2, 3), + intArrayOf(1, 3, 5), + intArrayOf(1, 4, 4), + intArrayOf(2, 5, 6), + ), + intArrayOf(2, 1, 2, 1, 3, 1), + ), + equalTo(intArrayOf(6, 2)), + ) + } + + @Test + fun longestSpecialPath2() { + assertThat( + Solution().longestSpecialPath(arrayOf(intArrayOf(1, 0, 8)), intArrayOf(2, 2)), + equalTo(intArrayOf(0, 1)), + ) + } +} diff --git a/src/test/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/SolutionTest.kt new file mode 100644 index 000000000..dd9344e10 --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3401_3500.s3426_manhattan_distances_of_all_arrangements_of_pieces + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun distanceSum() { + assertThat(Solution().distanceSum(2, 2, 2), equalTo(8)) + } + + @Test + fun distanceSum2() { + assertThat(Solution().distanceSum(1, 4, 3), equalTo(20)) + } +} diff --git a/src/test/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/SolutionTest.kt new file mode 100644 index 000000000..9fd8df42f --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3427_sum_of_variable_length_subarrays/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3401_3500.s3427_sum_of_variable_length_subarrays + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun subarraySum() { + assertThat(Solution().subarraySum(intArrayOf(2, 3, 1)), equalTo(11)) + } + + @Test + fun subarraySum2() { + assertThat(Solution().subarraySum(intArrayOf(3, 1, 1, 2)), equalTo(13)) + } +} diff --git a/src/test/kotlin/g3401_3500/s3428_maximum_and_minimum_sums_of_at_most_size_k_subsequences/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3428_maximum_and_minimum_sums_of_at_most_size_k_subsequences/SolutionTest.kt new file mode 100644 index 000000000..fca5e6394 --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3428_maximum_and_minimum_sums_of_at_most_size_k_subsequences/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3401_3500.s3428_maximum_and_minimum_sums_of_at_most_size_k_subsequences + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minMaxSums() { + assertThat(Solution().minMaxSums(intArrayOf(1, 2, 3), 2), equalTo(24)) + } + + @Test + fun minMaxSums2() { + assertThat(Solution().minMaxSums(intArrayOf(5, 0, 6), 1), equalTo(22)) + } +} diff --git a/src/test/kotlin/g3401_3500/s3429_paint_house_iv/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3429_paint_house_iv/SolutionTest.kt new file mode 100644 index 000000000..0eba3a6b2 --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3429_paint_house_iv/SolutionTest.kt @@ -0,0 +1,37 @@ +package g3401_3500.s3429_paint_house_iv + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minCost() { + assertThat( + Solution().minCost( + 4, + arrayOf(intArrayOf(3, 5, 7), intArrayOf(6, 2, 9), intArrayOf(4, 8, 1), intArrayOf(7, 3, 5)), + ), + equalTo(9L), + ) + } + + @Test + fun minCost2() { + assertThat( + Solution() + .minCost( + 6, + arrayOf( + intArrayOf(2, 4, 6), + intArrayOf(5, 3, 8), + intArrayOf(7, 1, 9), + intArrayOf(4, 6, 2), + intArrayOf(3, 5, 7), + intArrayOf(8, 2, 4), + ), + ), + equalTo(18L), + ) + } +} diff --git a/src/test/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/SolutionTest.kt b/src/test/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/SolutionTest.kt new file mode 100644 index 000000000..f909a54ad --- /dev/null +++ b/src/test/kotlin/g3401_3500/s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3401_3500.s3430_maximum_and_minimum_sums_of_at_most_size_k_subarrays + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minMaxSubarraySum() { + assertThat( + Solution().minMaxSubarraySum(intArrayOf(1, 2, 3), 2), + equalTo(20L), + ) + } + + @Test + fun minMaxSubarraySum2() { + assertThat( + Solution().minMaxSubarraySum(intArrayOf(1, -3, 1), 2), + equalTo(-6L), + ) + } +}