diff --git a/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.kt b/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.kt new file mode 100644 index 00000000..a43ace72 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.kt @@ -0,0 +1,32 @@ +package g3601_3700.s3678_smallest_absent_positive_greater_than_average + +// #Easy #Biweekly_Contest_165 #2025_09_20_Time_3_ms_(100.00%)_Space_47.84_MB_(100.00%) + +class Solution { + fun smallestAbsent(nums: IntArray): Int { + var sum = 0 + for (j in nums) { + sum += j + } + val avg = sum.toDouble() / nums.size + var num: Int + if (avg < 0) { + num = 1 + } else { + num = avg.toInt() + 1 + } + while (true) { + var flag = false + for (j in nums) { + if (num == j) { + flag = true + break + } + } + if (!flag && num > avg) { + return num + } + num++ + } + } +} diff --git a/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/readme.md b/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/readme.md new file mode 100644 index 00000000..ddcb9ae2 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/readme.md @@ -0,0 +1,47 @@ +3678\. Smallest Absent Positive Greater Than Average + +Easy + +You are given an integer array `nums`. + +Return the **smallest absent positive** integer in `nums` such that it is **strictly greater** than the **average** of all elements in `nums`. + +The **average** of an array is defined as the sum of all its elements divided by the number of elements. + +**Example 1:** + +**Input:** nums = [3,5] + +**Output:** 6 + +**Explanation:** + +* The average of `nums` is `(3 + 5) / 2 = 8 / 2 = 4`. +* The smallest absent positive integer greater than 4 is 6. + +**Example 2:** + +**Input:** nums = [-1,1,2] + +**Output:** 3 + +**Explanation:** + +* The average of `nums` is `(-1 + 1 + 2) / 3 = 2 / 3 = 0.667`. +* The smallest absent positive integer greater than 0.667 is 3. + +**Example 3:** + +**Input:** nums = [4,-1] + +**Output:** 2 + +**Explanation:** + +* The average of `nums` is `(4 + (-1)) / 2 = 3 / 2 = 1.50`. +* The smallest absent positive integer greater than 1.50 is 2. + +**Constraints:** + +* `1 <= nums.length <= 100` +* `-100 <= nums[i] <= 100` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.kt b/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.kt new file mode 100644 index 00000000..a77940cd --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.kt @@ -0,0 +1,33 @@ +package g3601_3700.s3679_minimum_discards_to_balance_inventory + +// #Medium #Biweekly_Contest_165 #2025_09_20_Time_6_ms_(100.00%)_Space_68.59_MB_(76.92%) + +import kotlin.math.max + +class Solution { + fun minArrivalsToDiscard(arrivals: IntArray, w: Int, m: Int): Int { + val n = arrivals.size + var dis = 0 + val removed = BooleanArray(n) + var maxVal = 0 + for (v in arrivals) { + maxVal = max(maxVal, v) + } + val freq = IntArray(maxVal + 1) + for (i in 0..= 0 && !removed[outIdx]) { + val oldVal = arrivals[outIdx] + freq[oldVal]-- + } + val `val` = arrivals[i] + if (freq[`val`] >= m) { + dis++ + removed[i] = true + } else { + freq[`val`]++ + } + } + return dis + } +} diff --git a/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/readme.md b/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/readme.md new file mode 100644 index 00000000..9030dfd8 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/readme.md @@ -0,0 +1,54 @@ +3679\. Minimum Discards to Balance Inventory + +Medium + +You are given two integers `w` and `m`, and an integer array `arrivals`, where `arrivals[i]` is the type of item arriving on day `i` (days are **1-indexed**). + +Items are managed according to the following rules: + +* Each arrival may be **kept** or **discarded**; an item may only be discarded on its arrival day. +* For each day `i`, consider the window of days `[max(1, i - w + 1), i]` (the `w` most recent days up to day `i`): + * For **any** such window, each item type may appear **at most** `m` times among kept arrivals whose arrival day lies in that window. + * If keeping the arrival on day `i` would cause its type to appear **more than** `m` times in the window, that arrival **must** be discarded. + +Return the **minimum** number of arrivals to be discarded so that every `w`\-day window contains at most `m` occurrences of each type. + +**Example 1:** + +**Input:** arrivals = [1,2,1,3,1], w = 4, m = 2 + +**Output:** 0 + +**Explanation:** + +* On day 1, Item 1 arrives; the window contains no more than `m` occurrences of this type, so we keep it. +* On day 2, Item 2 arrives; the window of days 1 - 2 is fine. +* On day 3, Item 1 arrives, window `[1, 2, 1]` has item 1 twice, within limit. +* On day 4, Item 3 arrives, window `[1, 2, 1, 3]` has item 1 twice, allowed. +* On day 5, Item 1 arrives, window `[2, 1, 3, 1]` has item 1 twice, still valid. + +There are no discarded items, so return 0. + +**Example 2:** + +**Input:** arrivals = [1,2,3,3,3,4], w = 3, m = 2 + +**Output:** 1 + +**Explanation:** + +* On day 1, Item 1 arrives. We keep it. +* On day 2, Item 2 arrives, window `[1, 2]` is fine. +* On day 3, Item 3 arrives, window `[1, 2, 3]` has item 3 once. +* On day 4, Item 3 arrives, window `[2, 3, 3]` has item 3 twice, allowed. +* On day 5, Item 3 arrives, window `[3, 3, 3]` has item 3 three times, exceeds limit, so the arrival must be discarded. +* On day 6, Item 4 arrives, window `[3, 4]` is fine. + +Item 3 on day 5 is discarded, and this is the minimum number of arrivals to discard, so return 1. + +**Constraints:** + +* 1 <= arrivals.length <= 105 +* 1 <= arrivals[i] <= 105 +* `1 <= w <= arrivals.length` +* `1 <= m <= w` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3680_generate_schedule/Solution.kt b/src/main/kotlin/g3601_3700/s3680_generate_schedule/Solution.kt new file mode 100644 index 00000000..34395c5b --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3680_generate_schedule/Solution.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3680_generate_schedule + +// #Medium #Biweekly_Contest_165 #2025_09_20_Time_3_ms_(100.00%)_Space_48.94_MB_(100.00%) + +class Solution { + fun generateSchedule(n: Int): Array { + if (n < 5) { + return Array(0) { IntArray(0) } + } + val res = Array(n * (n - 1)) { IntArray(2) } + var idx = 0 + for (i in 2.. y) { + y = v + } + } + if (y == 0) { + return x + } + x = max(x, x xor y) + for (i in 0..2 <= nums.length <= 105 +* 0 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.kt b/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.kt new file mode 100644 index 00000000..fa730b99 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.kt @@ -0,0 +1,17 @@ +package g3601_3700.s3683_earliest_time_to_finish_one_task + +// #Easy #Weekly_Contest_467 #2025_09_20_Time_1_ms_(100.00%)_Space_52.19_MB_(60.38%) + +import kotlin.math.min + +class Solution { + fun earliestTime(tasks: Array): Int { + var ans = 1000 + for (i in tasks.indices) { + val st = tasks[i][0] + val tm = tasks[i][1] + ans = min(ans, st + tm) + } + return ans + } +} diff --git a/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/readme.md b/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/readme.md new file mode 100644 index 00000000..5402f26d --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/readme.md @@ -0,0 +1,35 @@ +3683\. Earliest Time to Finish One Task + +Easy + +You are given a 2D integer array `tasks` where tasks[i] = [si, ti]. + +Each [si, ti] in `tasks` represents a task with start time si that takes ti units of time to finish. + +Return the earliest time at which at least one task is finished. + +**Example 1:** + +**Input:** tasks = [[1,6],[2,3]] + +**Output:** 5 + +**Explanation:** + +The first task starts at time `t = 1` and finishes at time `1 + 6 = 7`. The second task finishes at time `2 + 3 = 5`. You can finish one task at time 5. + +**Example 2:** + +**Input:** tasks = [[100,100],[100,100],[100,100]] + +**Output:** 200 + +**Explanation:** + +All three tasks finish at time `100 + 100 = 200`. + +**Constraints:** + +* `1 <= tasks.length <= 100` +* tasks[i] = [si, ti] +* 1 <= si, ti <= 100 \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.kt b/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.kt new file mode 100644 index 00000000..78602fe7 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.kt @@ -0,0 +1,33 @@ +package g3601_3700.s3684_maximize_sum_of_at_most_k_distinct_elements + +// #Easy #Weekly_Contest_467 #2025_09_20_Time_12_ms_(92.59%)_Space_50.11_MB_(90.74%) + +class Solution { + fun maxKDistinct(nums: IntArray, k: Int): IntArray { + nums.sort() + val arr = IntArray(k) + var j = 1 + arr[0] = nums[nums.size - 1] + if (nums.size > 1) { + var i = nums.size - 2 + while (j < k && i >= 0) { + if (i < nums.size - 1 && nums[i] != nums[i + 1]) { + arr[j] = nums[i] + j++ + } + i-- + } + } + var cnt = 0 + var n = 0 + while (n < arr.size) { + if (arr[n] != 0) { + cnt++ + } + n++ + } + val finl = IntArray(cnt) + System.arraycopy(arr, 0, finl, 0, cnt) + return finl + } +} diff --git a/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/readme.md b/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/readme.md new file mode 100644 index 00000000..d05c016a --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/readme.md @@ -0,0 +1,45 @@ +3684\. Maximize Sum of At Most K Distinct Elements + +Easy + +You are given a **positive** integer array `nums` and an integer `k`. + +Choose at most `k` elements from `nums` so that their sum is maximized. However, the chosen numbers must be **distinct**. + +Return an array containing the chosen numbers in **strictly descending** order. + +**Example 1:** + +**Input:** nums = [84,93,100,77,90], k = 3 + +**Output:** [100,93,90] + +**Explanation:** + +The maximum sum is 283, which is attained by choosing 93, 100 and 90. We rearrange them in strictly descending order as `[100, 93, 90]`. + +**Example 2:** + +**Input:** nums = [84,93,100,77,93], k = 3 + +**Output:** [100,93,84] + +**Explanation:** + +The maximum sum is 277, which is attained by choosing 84, 93 and 100. We rearrange them in strictly descending order as `[100, 93, 84]`. We cannot choose 93, 100 and 93 because the chosen numbers must be distinct. + +**Example 3:** + +**Input:** nums = [1,1,1,2,2,2], k = 6 + +**Output:** [2,1] + +**Explanation:** + +The maximum sum is 3, which is attained by choosing 1 and 2. We rearrange them in strictly descending order as `[2, 1]`. + +**Constraints:** + +* `1 <= nums.length <= 100` +* 1 <= nums[i] <= 109 +* `1 <= k <= nums.length` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.kt b/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.kt new file mode 100644 index 00000000..5c9b3834 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.kt @@ -0,0 +1,61 @@ +package g3601_3700.s3685_subsequence_sum_after_capping_elements + +// #Medium #Weekly_Contest_467 #2025_09_20_Time_33_ms_(100.00%)_Space_50.14_MB_(100.00%) + +import kotlin.math.min + +class Solution { + fun subsequenceSumAfterCapping(nums: IntArray, k: Int): BooleanArray { + val zolvarinte = nums + val n = zolvarinte.size + val answer = BooleanArray(n) + val maxV = n + val freq = IntArray(maxV + 2) + for (v in zolvarinte) { + if (v <= maxV) { + freq[v]++ + } + } + val cntGe = IntArray(maxV + 2) + cntGe[maxV] = freq[maxV] + for (x in maxV - 1 downTo 1) { + cntGe[x] = cntGe[x + 1] + freq[x] + } + val dp = BooleanArray(k + 1) + dp[0] = true + for (x in 1..n) { + val cnt = cntGe[x] + var ok = false + var maxM = cnt + val limit = k / x + if (maxM > limit) { + maxM = limit + } + for (m in 0..maxM) { + val rem = k - m * x + if (rem >= 0 && dp[rem]) { + ok = true + break + } + } + answer[x - 1] = ok + var c = freq[x] + if (c == 0) { + continue + } + var power = 1 + while (c > 0) { + val take = min(power, c) + val weight = take * x + for (s in k downTo weight) { + if (!dp[s] && dp[s - weight]) { + dp[s] = true + } + } + c -= take + power = power shl 1 + } + } + return answer + } +} diff --git a/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/readme.md b/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/readme.md new file mode 100644 index 00000000..ca0ee673 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/readme.md @@ -0,0 +1,40 @@ +3685\. Subsequence Sum After Capping Elements + +Medium + +You are given an integer array `nums` of size `n` and a positive integer `k`. + +An array **capped** by value `x` is obtained by replacing every element `nums[i]` with `min(nums[i], x)`. + +For each integer `x` from 1 to `n`, determine whether it is possible to choose a **subsequence** from the array capped by `x` such that the sum of the chosen elements is **exactly** `k`. + +Return a **0-indexed** boolean array `answer` of size `n`, where `answer[i]` is `true` if it is possible when using `x = i + 1`, and `false` otherwise. + +**Example 1:** + +**Input:** nums = [4,3,2,4], k = 5 + +**Output:** [false,false,true,true] + +**Explanation:** + +* For `x = 1`, the capped array is `[1, 1, 1, 1]`. Possible sums are `1, 2, 3, 4`, so it is impossible to form a sum of `5`. +* For `x = 2`, the capped array is `[2, 2, 2, 2]`. Possible sums are `2, 4, 6, 8`, so it is impossible to form a sum of `5`. +* For `x = 3`, the capped array is `[3, 3, 2, 3]`. A subsequence `[2, 3]` sums to `5`, so it is possible. +* For `x = 4`, the capped array is `[4, 3, 2, 4]`. A subsequence `[3, 2]` sums to `5`, so it is possible. + +**Example 2:** + +**Input:** nums = [1,2,3,4,5], k = 3 + +**Output:** [true,true,true,true,true] + +**Explanation:** + +For every value of `x`, it is always possible to select a subsequence from the capped array that sums exactly to `3`. + +**Constraints:** + +* `1 <= n == nums.length <= 4000` +* `1 <= nums[i] <= n` +* `1 <= k <= 4000` \ No newline at end of file diff --git a/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/Solution.kt b/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/Solution.kt new file mode 100644 index 00000000..ebfc25f3 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/Solution.kt @@ -0,0 +1,31 @@ +package g3601_3700.s3686_number_of_stable_subsequences + +// #Hard #Weekly_Contest_467 #2025_09_20_Time_11_ms_(100.00%)_Space_70.56_MB_(55.00%) + +class Solution { + fun countStableSubsequences(nums: IntArray): Int { + var e1: Long = 0 + var e2: Long = 0 + var o1: Long = 0 + var o2: Long = 0 + for (x in nums) { + if ((x and 1) == 0) { + val ne1: Long = (e1 + (o1 + o2 + 1)) % MOD + val ne2: Long = (e2 + e1) % MOD + e1 = ne1 + e2 = ne2 + } else { + val no1: Long = (o1 + (e1 + e2 + 1)) % MOD + val no2: Long = (o2 + o1) % MOD + o1 = no1 + o2 = no2 + } + } + val ans: Long = (e1 + e2 + o1 + o2) % MOD + return ans.toInt() + } + + companion object { + private const val MOD = 1000000007L + } +} diff --git a/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/readme.md b/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/readme.md new file mode 100644 index 00000000..571c5969 --- /dev/null +++ b/src/main/kotlin/g3601_3700/s3686_number_of_stable_subsequences/readme.md @@ -0,0 +1,38 @@ +3686\. Number of Stable Subsequences + +Hard + +You are given an integer array `nums`. + +A **subsequence** is **stable** if it does not contain **three consecutive** elements with the **same** parity when the subsequence is read **in order** (i.e., consecutive **inside the subsequence**). + +Return the number of stable subsequences. + +Since the answer may be too large, return it **modulo** 109 + 7. + +**Example 1:** + +**Input:** nums = [1,3,5] + +**Output:** 6 + +**Explanation:** + +* Stable subsequences are `[1]`, `[3]`, `[5]`, `[1, 3]`, `[1, 5]`, and `[3, 5]`. +* Subsequence `[1, 3, 5]` is not stable because it contains three consecutive odd numbers. Thus, the answer is 6. + +**Example 2:** + +**Input:** nums = [2,3,4,2] + +**Output:** 14 + +**Explanation:** + +* The only subsequence that is not stable is `[2, 4, 2]`, which contains three consecutive even numbers. +* All other subsequences are stable. Thus, the answer is 14. + +**Constraints:** + +* 1 <= nums.length <= 105 +* 1 <= nums[i] <= 105 \ No newline at end of file diff --git a/src/test/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.kt new file mode 100644 index 00000000..a871cd7b --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.kt @@ -0,0 +1,27 @@ +package g3601_3700.s3678_smallest_absent_positive_greater_than_average + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun smallestAbsent() { + assertThat(Solution().smallestAbsent(intArrayOf(3, 5)), equalTo(6)) + } + + @Test + fun smallestAbsent2() { + assertThat(Solution().smallestAbsent(intArrayOf(-1, 1, 2)), equalTo(3)) + } + + @Test + fun smallestAbsent3() { + assertThat(Solution().smallestAbsent(intArrayOf(4, -1)), equalTo(2)) + } + + @Test + fun smallestAbsent4() { + assertThat(Solution().smallestAbsent(intArrayOf(-2, -1)), equalTo(1)) + } +} diff --git a/src/test/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.kt new file mode 100644 index 00000000..487a3774 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3679_minimum_discards_to_balance_inventory + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun minArrivalsToDiscard() { + assertThat( + Solution().minArrivalsToDiscard(intArrayOf(1, 2, 1, 3, 1), 4, 2), + equalTo(0), + ) + } + + @Test + fun minArrivalsToDiscard2() { + assertThat( + Solution().minArrivalsToDiscard(intArrayOf(1, 2, 3, 3, 3, 4), 3, 2), + equalTo(1), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3680_generate_schedule/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3680_generate_schedule/SolutionTest.kt new file mode 100644 index 00000000..30a4becb --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3680_generate_schedule/SolutionTest.kt @@ -0,0 +1,43 @@ +package g3601_3700.s3680_generate_schedule + +import org.hamcrest.CoreMatchers +import org.hamcrest.MatcherAssert +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun generateSchedule() { + MatcherAssert.assertThat>(Solution().generateSchedule(3), CoreMatchers.equalTo(intArrayOf())) + } + + @Test + fun generateSchedule2() { + MatcherAssert.assertThat>( + Solution().generateSchedule(5), + CoreMatchers.equalTo>( + arrayOf( + intArrayOf(0, 2), + intArrayOf(1, 3), + intArrayOf(2, 4), + intArrayOf(3, 0), + intArrayOf(4, 1), + intArrayOf(0, 3), + intArrayOf(1, 4), + intArrayOf(2, 0), + intArrayOf(3, 1), + intArrayOf(4, 2), + intArrayOf(0, 1), + intArrayOf(4, 3), + intArrayOf(1, 2), + intArrayOf(0, 4), + intArrayOf(2, 3), + intArrayOf(1, 0), + intArrayOf(3, 4), + intArrayOf(2, 1), + intArrayOf(4, 0), + intArrayOf(3, 2), + ), + ), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.kt new file mode 100644 index 00000000..f26736d1 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.kt @@ -0,0 +1,20 @@ +package g3601_3700.s3681_maximum_xor_of_subsequences + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun maxXorSubsequences() { + assertThat( + Solution().maxXorSubsequences(intArrayOf(1, 2, 3)), + equalTo(3), + ) + } + + @Test + fun maxXorSubsequences2() { + assertThat(Solution().maxXorSubsequences(intArrayOf(5, 2)), equalTo(7)) + } +} diff --git a/src/test/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.kt new file mode 100644 index 00000000..21b57cf8 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.kt @@ -0,0 +1,37 @@ +package g3601_3700.s3683_earliest_time_to_finish_one_task + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun earliestTime() { + assertThat( + Solution().earliestTime(arrayOf(intArrayOf(1, 6), intArrayOf(2, 3))), + equalTo(5), + ) + } + + @Test + fun earliestTime2() { + assertThat( + Solution().earliestTime( + arrayOf( + intArrayOf(100, 100), + intArrayOf(100, 100), + intArrayOf(100, 100), + ), + ), + equalTo(200), + ) + } + + @Test + fun earliestTime3() { + assertThat( + Solution().earliestTime(arrayOf(intArrayOf(1, 6))), + equalTo(7), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.kt new file mode 100644 index 00000000..816d5a41 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.kt @@ -0,0 +1,31 @@ +package g3601_3700.s3684_maximize_sum_of_at_most_k_distinct_elements + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun maxKDistinct() { + assertThat( + Solution().maxKDistinct(intArrayOf(84, 93, 100, 77, 90), 3), + equalTo(intArrayOf(100, 93, 90)), + ) + } + + @Test + fun maxKDistinct2() { + assertThat( + Solution().maxKDistinct(intArrayOf(84, 93, 100, 77, 93), 3), + equalTo(intArrayOf(100, 93, 84)), + ) + } + + @Test + fun maxKDistinct3() { + assertThat( + Solution().maxKDistinct(intArrayOf(1, 1, 1, 2, 2, 2), 6), + equalTo(intArrayOf(2, 1)), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.kt new file mode 100644 index 00000000..dc7129c8 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3685_subsequence_sum_after_capping_elements + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun subsequenceSumAfterCapping() { + assertThat( + Solution().subsequenceSumAfterCapping(intArrayOf(4, 3, 2, 4), 5), + equalTo(booleanArrayOf(false, false, true, true)), + ) + } + + @Test + fun subsequenceSumAfterCapping2() { + assertThat( + Solution().subsequenceSumAfterCapping(intArrayOf(1, 2, 3, 4, 5), 3), + equalTo(booleanArrayOf(true, true, true, true, true)), + ) + } +} diff --git a/src/test/kotlin/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.kt b/src/test/kotlin/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.kt new file mode 100644 index 00000000..2c1f5dc0 --- /dev/null +++ b/src/test/kotlin/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.kt @@ -0,0 +1,23 @@ +package g3601_3700.s3686_number_of_stable_subsequences + +import org.hamcrest.CoreMatchers.equalTo +import org.hamcrest.MatcherAssert.assertThat +import org.junit.jupiter.api.Test + +internal class SolutionTest { + @Test + fun countStableSubsequences() { + assertThat( + Solution().countStableSubsequences(intArrayOf(1, 3, 5)), + equalTo(6), + ) + } + + @Test + fun countStableSubsequences2() { + assertThat( + Solution().countStableSubsequences(intArrayOf(2, 3, 4, 2)), + equalTo(14), + ) + } +}