diff --git a/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/Solution.kt b/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/Solution.kt new file mode 100644 index 00000000..13962606 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/Solution.kt @@ -0,0 +1,15 @@ +package g3001_3100.s3065_minimum_operations_to_exceed_threshold_value_i + +// #Easy #Array #2024_03_31_Time_180_ms_(71.76%)_Space_36.9_MB_(81.18%) + +class Solution { + fun minOperations(nums: IntArray, k: Int): Int { + var count = 0 + for (num in nums) { + if (num >= k) { + count++ + } + } + return nums.size - count + } +} diff --git a/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/readme.md b/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/readme.md new file mode 100644 index 00000000..e4ecaf1d --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/readme.md @@ -0,0 +1,48 @@ +3065\. Minimum Operations to Exceed Threshold Value I + +Easy + +You are given a **0-indexed** integer array `nums`, and an integer `k`. + +In one operation, you can remove one occurrence of the smallest element of `nums`. + +Return _the **minimum** number of operations needed so that all elements of the array are greater than or equal to_ `k`. + +**Example 1:** + +**Input:** nums = [2,11,10,1,3], k = 10 + +**Output:** 3 + +**Explanation:** After one operation, nums becomes equal to [2, 11, 10, 3]. + +After two operations, nums becomes equal to [11, 10, 3]. + +After three operations, nums becomes equal to [11, 10]. + +At this stage, all the elements of nums are greater than or equal to 10 so we can stop. + +It can be shown that 3 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10. + +**Example 2:** + +**Input:** nums = [1,1,2,4,9], k = 1 + +**Output:** 0 + +**Explanation:** All elements of the array are greater than or equal to 1 so we do not need to apply any operations on nums. + +**Example 3:** + +**Input:** nums = [1,1,2,4,9], k = 9 + +**Output:** 4 + +**Explanation:** only a single element of nums is greater than or equal to 9 so we need to apply the operations 4 times on nums. + +**Constraints:** + +* `1 <= nums.length <= 50` +* 1 <= nums[i] <= 109 +* 1 <= k <= 109 +* The input is generated such that there is at least one index `i` such that `nums[i] >= k`. \ No newline at end of file diff --git a/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/Solution.kt b/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/Solution.kt new file mode 100644 index 00000000..7e3adc97 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/Solution.kt @@ -0,0 +1,36 @@ +package g3001_3100.s3066_minimum_operations_to_exceed_threshold_value_ii + +// #Medium #Array #Heap_Priority_Queue #Simulation +// #2024_03_31_Time_543_ms_(98.11%)_Space_73.7_MB_(86.79%) + +class Solution { + fun minOperations(nums: IntArray, k: Int): Int { + val n = nums.size + var steps = 0 + nums.sort() + val extra: MutableList = ArrayList() + var i = 0 + var j = 0 + while ((i < n && nums[i] < k) || (j < extra.size && extra[j] < k)) { + val min = if (i < n && (j >= extra.size || extra[j] > nums[i])) { + nums[i++] + } else { + extra[j++] + } + val max = if (i < n && (j >= extra.size || extra[j] > nums[i])) { + nums[i++] + } else { + extra[j++] + } + steps++ + var res = min.toLong() + res = 2 * res + max + if (res > Int.MAX_VALUE) { + extra.add(Int.MAX_VALUE) + } else { + extra.add(res.toInt()) + } + } + return steps + } +} diff --git a/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/readme.md b/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/readme.md new file mode 100644 index 00000000..f8f651e3 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/readme.md @@ -0,0 +1,54 @@ +3066\. Minimum Operations to Exceed Threshold Value II + +Medium + +You are given a **0-indexed** integer array `nums`, and an integer `k`. + +In one operation, you will: + +* Take the two smallest integers `x` and `y` in `nums`. +* Remove `x` and `y` from `nums`. +* Add `min(x, y) * 2 + max(x, y)` anywhere in the array. + +**Note** that you can only apply the described operation if `nums` contains at least two elements. + +Return _the **minimum** number of operations needed so that all elements of the array are greater than or equal to_ `k`. + +**Example 1:** + +**Input:** nums = [2,11,10,1,3], k = 10 + +**Output:** 2 + +**Explanation:** In the first operation, we remove elements 1 and 2, then add 1 \* 2 + 2 to nums. nums becomes equal to [4, 11, 10, 3]. + +In the second operation, we remove elements 3 and 4, then add 3 \* 2 + 4 to nums. nums becomes equal to [10, 11, 10]. + +At this stage, all the elements of nums are greater than or equal to 10 so we can stop. + +It can be shown that 2 is the minimum number of operations needed so that all elements of the array are greater than or equal to 10. + +**Example 2:** + +**Input:** nums = [1,1,2,4,9], k = 20 + +**Output:** 4 + +**Explanation:** After one operation, nums becomes equal to [2, 4, 9, 3]. + +After two operations, nums becomes equal to [7, 4, 9]. + +After three operations, nums becomes equal to [15, 9]. + +After four operations, nums becomes equal to [33]. + +At this stage, all the elements of nums are greater than 20 so we can stop. + +It can be shown that 4 is the minimum number of operations needed so that all elements of the array are greater than or equal to 20. + +**Constraints:** + +* 2 <= nums.length <= 2 * 105 +* 1 <= nums[i] <= 109 +* 1 <= k <= 109 +* The input is generated such that an answer always exists. That is, there exists some sequence of operations after which all elements of the array are greater than or equal to `k`. \ No newline at end of file diff --git a/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/Solution.kt b/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/Solution.kt new file mode 100644 index 00000000..e2d0a5ce --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/Solution.kt @@ -0,0 +1,58 @@ +package g3001_3100.s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network + +// #Medium #Array #Depth_First_Search #Tree #2024_03_31_Time_578_ms_(83.33%)_Space_59.5_MB_(45.83%) + +@Suppress("NAME_SHADOWING") +class Solution { + private lateinit var adj: Array> + + fun countPairsOfConnectableServers(edges: Array, signalSpeed: Int): IntArray { + val n = edges.size + 1 + adj = Array(n) { ArrayList() } + for (i in 0 until n) { + adj[i] = ArrayList() + } + for (edge in edges) { + val u = edge[0] + val v = edge[1] + val w = edge[2] + adj[u].add(v) + adj[v].add(u) + adj[u].add(w) + adj[v].add(w) + } + val res = IntArray(n) + for (i in 0 until n) { + if (adj[i].size > 2) { + val al = ArrayList() + var j = 0 + while (j < adj[i].size) { + val cnt = IntArray(1) + dfs(adj[i][j], i, adj[i][j + 1], cnt, signalSpeed) + al.add(cnt[0]) + j += 2 + } + var sum = 0 + for (j in al) { + res[i] += (sum * j) + sum += j + } + } + } + return res + } + + fun dfs(node: Int, par: Int, sum: Int, cnt: IntArray, ss: Int) { + if (sum % ss == 0) { + cnt[0]++ + } + var i = 0 + while (i < adj[node].size) { + val child = adj[node][i] + if (child != par) { + dfs(child, node, sum + adj[node][i + 1], cnt, ss) + } + i += 2 + } + } +} diff --git a/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/readme.md b/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/readme.md new file mode 100644 index 00000000..d4b28955 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/readme.md @@ -0,0 +1,51 @@ +3067\. Count Pairs of Connectable Servers in a Weighted Tree Network + +Medium + +You are given an unrooted weighted tree with `n` vertices representing servers numbered from `0` to `n - 1`, an array `edges` where edges[i] = [ai, bi, weighti] represents a bidirectional edge between vertices ai and bi of weight weighti. You are also given an integer `signalSpeed`. + +Two servers `a` and `b` are **connectable** through a server `c` if: + +* `a < b`, `a != c` and `b != c`. +* The distance from `c` to `a` is divisible by `signalSpeed`. +* The distance from `c` to `b` is divisible by `signalSpeed`. +* The path from `c` to `b` and the path from `c` to `a` do not share any edges. + +Return _an integer array_ `count` _of length_ `n` _where_ `count[i]` _is the **number** of server pairs that are **connectable** through_ _the server_ `i`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2024/01/21/example22.png) + +**Input:** edges = [[0,1,1],[1,2,5],[2,3,13],[3,4,9],[4,5,2]], signalSpeed = 1 + +**Output:** [0,4,6,6,4,0] + +**Explanation:** Since signalSpeed is 1, count[c] is equal to the number of pairs of paths that start at c and do not share any edges. + +In the case of the given path graph, count[c] is equal to the number of servers to the left of c multiplied by the servers to the right of c. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2024/01/21/example11.png) + +**Input:** edges = [[0,6,3],[6,5,3],[0,3,1],[3,2,7],[3,1,6],[3,4,2]], signalSpeed = 3 + +**Output:** [2,0,0,0,0,0,2] + +**Explanation:** Through server 0, there are 2 pairs of connectable servers: (4, 5) and (4, 6). + +Through server 6, there are 2 pairs of connectable servers: (4, 5) and (0, 5). + +It can be shown that no two servers are connectable through servers other than 0 and 6. + +**Constraints:** + +* `2 <= n <= 1000` +* `edges.length == n - 1` +* `edges[i].length == 3` +* 0 <= ai, bi < n +* edges[i] = [ai, bi, weighti] +* 1 <= weighti <= 106 +* 1 <= signalSpeed <= 106 +* The input is generated such that `edges` represents a valid tree. \ No newline at end of file diff --git a/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/Solution.kt b/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/Solution.kt new file mode 100644 index 00000000..ba77a7a5 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/Solution.kt @@ -0,0 +1,24 @@ +package g3001_3100.s3068_find_the_maximum_sum_of_node_values + +// #Hard #Array #Dynamic_Programming #Sorting #Greedy #Tree #Bit_Manipulation +// #2024_03_31_Time_531_ms_(66.67%)_Space_64.9_MB_(66.67%) + +import kotlin.math.abs +import kotlin.math.max +import kotlin.math.min + +@Suppress("UNUSED_PARAMETER") +class Solution { + fun maximumValueSum(nums: IntArray, k: Int, edges: Array?): Long { + var res: Long = 0 + var d = 1 shl 30 + var c = 0 + for (a in nums) { + val b = a xor k + res += max(a, b) + c = c xor if (a < b) 1 else 0 + d = min(d, abs((a - b))) + } + return res - d * c + } +} diff --git a/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/readme.md b/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/readme.md new file mode 100644 index 00000000..31e9d00e --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/readme.md @@ -0,0 +1,65 @@ +3068\. Find the Maximum Sum of Node Values + +Hard + +There exists an **undirected** tree with `n` nodes numbered `0` to `n - 1`. You are given a **0-indexed** 2D integer array `edges` of length `n - 1`, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree. You are also given a **positive** integer `k`, and a **0-indexed** array of **non-negative** integers `nums` of length `n`, where `nums[i]` represents the **value** of the node numbered `i`. + +Alice wants the sum of values of tree nodes to be **maximum**, for which Alice can perform the following operation **any** number of times (**including zero**) on the tree: + +* Choose any edge `[u, v]` connecting the nodes `u` and `v`, and update their values as follows: + * `nums[u] = nums[u] XOR k` + * `nums[v] = nums[v] XOR k` + +Return _the **maximum** possible **sum** of the **values** Alice can achieve by performing the operation **any** number of times_. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2023/11/09/screenshot-2023-11-10-012513.png) + +**Input:** nums = [1,2,1], k = 3, edges = [[0,1],[0,2]] + +**Output:** 6 + +**Explanation:** Alice can achieve the maximum sum of 6 using a single operation: + +- Choose the edge [0,2]. nums[0] and nums[2] become: 1 XOR 3 = 2, and the array nums becomes: [1,2,1] -> [2,2,2]. + +The total sum of values is 2 + 2 + 2 = 6. + +It can be shown that 6 is the maximum achievable sum of values. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2024/01/09/screenshot-2024-01-09-220017.png) + +**Input:** nums = [2,3], k = 7, edges = [[0,1]] + +**Output:** 9 + +**Explanation:** Alice can achieve the maximum sum of 9 using a single operation: + +- Choose the edge [0,1]. nums[0] becomes: 2 XOR 7 = 5 and nums[1] become: 3 XOR 7 = 4, and the array nums becomes: [2,3] -> [5,4]. + +The total sum of values is 5 + 4 = 9. + +It can be shown that 9 is the maximum achievable sum of values. + +**Example 3:** + +![](https://assets.leetcode.com/uploads/2023/11/09/screenshot-2023-11-10-012641.png) + +**Input:** nums = [7,7,7,7,7,7], k = 3, edges = [[0,1],[0,2],[0,3],[0,4],[0,5]] + +**Output:** 42 + +**Explanation:** The maximum achievable sum is 42 which can be achieved by Alice performing no operations. + +**Constraints:** + +* 2 <= n == nums.length <= 2 * 104 +* 1 <= k <= 109 +* 0 <= nums[i] <= 109 +* `edges.length == n - 1` +* `edges[i].length == 2` +* `0 <= edges[i][0], edges[i][1] <= n - 1` +* The input is generated such that `edges` represent a valid tree. \ No newline at end of file diff --git a/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/Solution.kt b/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/Solution.kt new file mode 100644 index 00000000..9ca89f51 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/Solution.kt @@ -0,0 +1,32 @@ +package g3001_3100.s3069_distribute_elements_into_two_arrays_i + +// #Easy #Array #Simulation #2024_03_31_Time_207_ms_(96.92%)_Space_37.5_MB_(87.69%) + +class Solution { + fun resultArray(nums: IntArray): IntArray { + var s = 0 + var t = 1 + for (i in 2 until nums.size) { + var p = i + if (nums[s] > nums[t]) { + for (q in s + 1 until i) { + val temp = nums[p] + nums[p] = nums[p - 1] + nums[p - 1] = temp + p -= 1 + } + s++ + t++ + } else { + for (q in t + 1 until i) { + val temp = nums[p] + nums[p] = nums[p - 1] + nums[p - 1] = temp + p -= 1 + } + t++ + } + } + return nums + } +} diff --git a/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/readme.md b/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/readme.md new file mode 100644 index 00000000..6942ede4 --- /dev/null +++ b/src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/readme.md @@ -0,0 +1,49 @@ +3069\. Distribute Elements Into Two Arrays I + +Easy + +You are given a **1-indexed** array of **distinct** integers `nums` of length `n`. + +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 the last element of `arr1` is **greater** than the last element of `arr2`, append `nums[i]` to `arr1`. Otherwise, append `nums[i]` to `arr2`. + +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 array_ `result`. + +**Example 1:** + +**Input:** nums = [2,1,3] + +**Output:** [2,3,1] + +**Explanation:** After the first 2 operations, arr1 = [2] and arr2 = [1]. + +In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (2 > 1), append nums[3] to arr1. + +After 3 operations, arr1 = [2,3] and arr2 = [1]. + +Hence, the array result formed by concatenation is [2,3,1]. + +**Example 2:** + +**Input:** nums = [5,4,3,8] + +**Output:** [5,3,4,8] + +**Explanation:** After the first 2 operations, arr1 = [5] and arr2 = [4]. + +In the 3rd operation, as the last element of arr1 is greater than the last element of arr2 (5 > 4), append nums[3] to arr1, hence arr1 becomes [5,3]. + +In the 4th operation, as the last element of arr2 is greater than the last element of arr1 (4 > 3), append nums[4] to arr2, hence arr2 becomes [4,8]. + +After 4 operations, arr1 = [5,3] and arr2 = [4,8]. + +Hence, the array result formed by concatenation is [5,3,4,8]. + +**Constraints:** + +* `3 <= n <= 50` +* `1 <= nums[i] <= 100` +* All elements in `nums` are distinct. \ No newline at end of file diff --git a/src/test/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/SolutionTest.kt new file mode 100644 index 00000000..82f4dd91 --- /dev/null +++ b/src/test/kotlin/g3001_3100/s3065_minimum_operations_to_exceed_threshold_value_i/SolutionTest.kt @@ -0,0 +1,22 @@ +package g3001_3100.s3065_minimum_operations_to_exceed_threshold_value_i + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minOperations() { + assertThat(Solution().minOperations(intArrayOf(2, 11, 10, 1, 3), 10), equalTo(3)) + } + + @Test + fun minOperations2() { + assertThat(Solution().minOperations(intArrayOf(1, 1, 2, 4, 9), 1), equalTo(0)) + } + + @Test + fun minOperations3() { + assertThat(Solution().minOperations(intArrayOf(1, 1, 2, 4, 9), 9), equalTo(4)) + } +} diff --git a/src/test/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/SolutionTest.kt new file mode 100644 index 00000000..1b2cf81a --- /dev/null +++ b/src/test/kotlin/g3001_3100/s3066_minimum_operations_to_exceed_threshold_value_ii/SolutionTest.kt @@ -0,0 +1,17 @@ +package g3001_3100.s3066_minimum_operations_to_exceed_threshold_value_ii + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minOperations() { + assertThat(Solution().minOperations(intArrayOf(2, 11, 10, 1, 3), 10), equalTo(2)) + } + + @Test + fun minOperations2() { + assertThat(Solution().minOperations(intArrayOf(1, 1, 2, 4, 9), 20), equalTo(4)) + } +} diff --git a/src/test/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/SolutionTest.kt new file mode 100644 index 00000000..34249b08 --- /dev/null +++ b/src/test/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network/SolutionTest.kt @@ -0,0 +1,44 @@ +package g3001_3100.s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun countPairsOfConnectableServers() { + assertThat( + Solution() + .countPairsOfConnectableServers( + arrayOf( + intArrayOf(0, 1, 1), + intArrayOf(1, 2, 5), + intArrayOf(2, 3, 13), + intArrayOf(3, 4, 9), + intArrayOf(4, 5, 2) + ), + 1 + ), + equalTo(intArrayOf(0, 4, 6, 6, 4, 0)) + ) + } + + @Test + fun countPairsOfConnectableServers2() { + assertThat( + Solution() + .countPairsOfConnectableServers( + arrayOf( + intArrayOf(0, 6, 3), + intArrayOf(6, 5, 3), + intArrayOf(0, 3, 1), + intArrayOf(3, 2, 7), + intArrayOf(3, 1, 6), + intArrayOf(3, 4, 2) + ), + 3 + ), + equalTo(intArrayOf(2, 0, 0, 0, 0, 0, 2)) + ) + } +} diff --git a/src/test/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/SolutionTest.kt new file mode 100644 index 00000000..78854b05 --- /dev/null +++ b/src/test/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values/SolutionTest.kt @@ -0,0 +1,37 @@ +package g3001_3100.s3068_find_the_maximum_sum_of_node_values + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun maximumValueSum() { + assertThat( + Solution() + .maximumValueSum(intArrayOf(1, 2, 1), 3, arrayOf(intArrayOf(0, 1), intArrayOf(0, 2))), + equalTo(6L) + ) + } + + @Test + fun maximumValueSum2() { + assertThat( + Solution().maximumValueSum(intArrayOf(2, 3), 7, arrayOf(intArrayOf(0, 1))), + equalTo(9L) + ) + } + + @Test + fun maximumValueSum3() { + assertThat( + Solution() + .maximumValueSum( + intArrayOf(7, 7, 7, 7, 7, 7), + 3, + arrayOf(intArrayOf(0, 1), intArrayOf(0, 2), intArrayOf(0, 3), intArrayOf(0, 4), intArrayOf(0, 5)) + ), + equalTo(42L) + ) + } +} diff --git a/src/test/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/SolutionTest.kt b/src/test/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/SolutionTest.kt new file mode 100644 index 00000000..46e99907 --- /dev/null +++ b/src/test/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i/SolutionTest.kt @@ -0,0 +1,20 @@ +package g3001_3100.s3069_distribute_elements_into_two_arrays_i + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun resultArray() { + assertThat(Solution().resultArray(intArrayOf(2, 1, 3)), equalTo(intArrayOf(2, 3, 1))) + } + + @Test + fun resultArray2() { + assertThat( + Solution().resultArray(intArrayOf(5, 4, 3, 8)), + equalTo(intArrayOf(5, 3, 4, 8)) + ) + } +}