diff --git a/src/main/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.java b/src/main/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.java new file mode 100644 index 000000000..4be70b86f --- /dev/null +++ b/src/main/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/Solution.java @@ -0,0 +1,32 @@ +package g3601_3700.s3678_smallest_absent_positive_greater_than_average; + +// #Easy #Biweekly_Contest_165 #2025_09_20_Time_2_ms_(100.00%)_Space_45.28_MB_(53.71%) + +public class Solution { + public int smallestAbsent(int[] nums) { + int sum = 0; + for (int j : nums) { + sum += j; + } + double avg = (double) sum / nums.length; + int num; + if (avg < 0) { + num = 1; + } else { + num = (int) avg + 1; + } + while (true) { + boolean flag = false; + for (int j : nums) { + if (num == j) { + flag = true; + break; + } + } + if (!flag && num > avg) { + return num; + } + num++; + } + } +} diff --git a/src/main/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/readme.md b/src/main/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/readme.md new file mode 100644 index 000000000..ddcb9ae29 --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.java b/src/main/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.java new file mode 100644 index 000000000..0f1dc347e --- /dev/null +++ b/src/main/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/Solution.java @@ -0,0 +1,31 @@ +package g3601_3700.s3679_minimum_discards_to_balance_inventory; + +// #Medium #Biweekly_Contest_165 #2025_09_20_Time_2_ms_(100.00%)_Space_60.72_MB_(75.43%) + +public class Solution { + public int minArrivalsToDiscard(int[] arrivals, int w, int m) { + int n = arrivals.length; + int dis = 0; + boolean[] removed = new boolean[n]; + int maxVal = 0; + for (int v : arrivals) { + maxVal = Math.max(maxVal, v); + } + int[] freq = new int[maxVal + 1]; + for (int i = 0; i < n; i++) { + int outIdx = i - w; + if (outIdx >= 0 && !removed[outIdx]) { + int oldVal = arrivals[outIdx]; + freq[oldVal]--; + } + int val = arrivals[i]; + if (freq[val] >= m) { + dis++; + removed[i] = true; + } else { + freq[val]++; + } + } + return dis; + } +} diff --git a/src/main/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/readme.md b/src/main/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/readme.md new file mode 100644 index 000000000..9030dfd89 --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3680_generate_schedule/Solution.java b/src/main/java/g3601_3700/s3680_generate_schedule/Solution.java new file mode 100644 index 000000000..4392cec4d --- /dev/null +++ b/src/main/java/g3601_3700/s3680_generate_schedule/Solution.java @@ -0,0 +1,23 @@ +package g3601_3700.s3680_generate_schedule; + +// #Medium #Biweekly_Contest_165 #2025_09_20_Time_2_ms_(100.00%)_Space_45.33_MB_(59.29%) + +public class Solution { + public int[][] generateSchedule(int n) { + if (n < 5) { + return new int[0][]; + } + int[][] res = new int[n * (n - 1)][]; + int idx = 0; + for (int i = 2; i < n - 1; i++) { + for (int j = 0; j < n; j++) { + res[idx++] = new int[] {j, (j + i) % n}; + } + } + for (int i = 0; i < n; i++) { + res[idx++] = new int[] {i, (i + 1) % n}; + res[idx++] = new int[] {(i + 4) % n, (i + 3) % n}; + } + return res; + } +} diff --git a/src/main/java/g3601_3700/s3680_generate_schedule/readme.md b/src/main/java/g3601_3700/s3680_generate_schedule/readme.md new file mode 100644 index 000000000..71a7cc8c2 --- /dev/null +++ b/src/main/java/g3601_3700/s3680_generate_schedule/readme.md @@ -0,0 +1,41 @@ +3680\. Generate Schedule + +Medium + +You are given an integer `n` representing `n` teams. You are asked to generate a schedule such that: + +* Each team plays every other team **exactly twice**: once at home and once away. +* There is **exactly one** match per day; the schedule is a list of **consecutive** days and `schedule[i]` is the match on day `i`. +* No team plays on **consecutive** days. + +Return a 2D integer array `schedule`, where `schedule[i][0]` represents the home team and `schedule[i][1]` represents the away team. If multiple schedules meet the conditions, return **any** one of them. + +If no schedule exists that meets the conditions, return an empty array. + +**Example 1:** + +**Input:** n = 3 + +**Output:** [] + +**Explanation:** + +Since each team plays every other team exactly twice, a total of 6 matches need to be played: `[0,1],[0,2],[1,2],[1,0],[2,0],[2,1]`. + +It's not possible to create a schedule without at least one team playing consecutive days. + +**Example 2:** + +**Input:** n = 5 + +**Output:** [[0,1],[2,3],[0,4],[1,2],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[2,0],[3,1],[4,0],[2,1],[4,3],[1,0],[3,2],[4,1],[3,0],[4,2]] + +**Explanation:** + +Since each team plays every other team exactly twice, a total of 20 matches need to be played. + +The output shows one of the schedules that meet the conditions. No team plays on consecutive days. + +**Constraints:** + +* `2 <= n <= 50` \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/Solution.java b/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/Solution.java new file mode 100644 index 000000000..628667fd2 --- /dev/null +++ b/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/Solution.java @@ -0,0 +1,29 @@ +package g3601_3700.s3681_maximum_xor_of_subsequences; + +// #Hard #Biweekly_Contest_165 #2025_09_20_Time_27_ms_(99.73%)_Space_58.35_MB_(30.31%) + +public class Solution { + public int maxXorSubsequences(int[] nums) { + int n = nums.length; + if (n == 0) { + return 0; + } + int x = 0; + while (true) { + int y = 0; + for (int v : nums) { + if (v > y) { + y = v; + } + } + if (y == 0) { + return x; + } + x = Math.max(x, x ^ y); + for (int i = 0; i < n; i++) { + int v = nums[i]; + nums[i] = Math.min(v, v ^ y); + } + } + } +} diff --git a/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/readme.md b/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/readme.md new file mode 100644 index 000000000..9d5d32c6e --- /dev/null +++ b/src/main/java/g3601_3700/s3681_maximum_xor_of_subsequences/readme.md @@ -0,0 +1,53 @@ +3681\. Maximum XOR of Subsequences + +Hard + +You are given an integer array `nums` of length `n` where each element is a non-negative integer. + +Select **two** **subsequences** of `nums` (they may be empty and are **allowed** to **overlap**), each preserving the original order of elements, and let: + +* `X` be the bitwise XOR of all elements in the first subsequence. +* `Y` be the bitwise XOR of all elements in the second subsequence. + +Return the **maximum** possible value of `X XOR Y`. + +**Note:** The XOR of an **empty** subsequence is 0. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** 3 + +**Explanation:** + +Choose subsequences: + +* First subsequence `[2]`, whose XOR is 2. +* Second subsequence `[2,3]`, whose XOR is 1. + +Then, XOR of both subsequences = `2 XOR 1 = 3`. + +This is the maximum XOR value achievable from any two subsequences. + +**Example 2:** + +**Input:** nums = [5,2] + +**Output:** 7 + +**Explanation:** + +Choose subsequences: + +* First subsequence `[5]`, whose XOR is 5. +* Second subsequence `[2]`, whose XOR is 2. + +Then, XOR of both subsequences = `5 XOR 2 = 7`. + +This is the maximum XOR value achievable from any two subsequences. + +**Constraints:** + +* 2 <= nums.length <= 105 +* 0 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.java b/src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.java new file mode 100644 index 000000000..908327c82 --- /dev/null +++ b/src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/Solution.java @@ -0,0 +1,15 @@ +package g3601_3700.s3683_earliest_time_to_finish_one_task; + +// #Easy #Weekly_Contest_467 #2025_09_20_Time_0_ms_(100.00%)_Space_45.29_MB_(39.62%) + +public class Solution { + public int earliestTime(int[][] tasks) { + int ans = 1000; + for (int i = 0; i < tasks.length; i++) { + int st = tasks[i][0]; + int tm = tasks[i][1]; + ans = Math.min(ans, st + tm); + } + return ans; + } +} diff --git a/src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/readme.md b/src/main/java/g3601_3700/s3683_earliest_time_to_finish_one_task/readme.md new file mode 100644 index 000000000..5402f26de --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.java b/src/main/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.java new file mode 100644 index 000000000..a12e778ea --- /dev/null +++ b/src/main/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/Solution.java @@ -0,0 +1,33 @@ +package g3601_3700.s3684_maximize_sum_of_at_most_k_distinct_elements; + +// #Easy #Weekly_Contest_467 #2025_09_20_Time_2_ms_(100.00%)_Space_45.58_MB_(68.55%) + +import java.util.Arrays; + +public class Solution { + public int[] maxKDistinct(int[] nums, int k) { + Arrays.sort(nums); + int[] arr = new int[k]; + int j = 1; + arr[0] = nums[nums.length - 1]; + if (nums.length > 1) { + for (int i = nums.length - 2; j < k && i >= 0; i--) { + if (i < nums.length - 1 && nums[i] != nums[i + 1]) { + arr[j] = nums[i]; + j++; + } + } + } + int cnt = 0; + int n = 0; + while (n < arr.length) { + if (arr[n] != 0) { + cnt++; + } + n++; + } + int[] finl = new int[cnt]; + System.arraycopy(arr, 0, finl, 0, cnt); + return finl; + } +} diff --git a/src/main/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/readme.md b/src/main/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/readme.md new file mode 100644 index 000000000..d05c016a7 --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.java b/src/main/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.java new file mode 100644 index 000000000..869820f65 --- /dev/null +++ b/src/main/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/Solution.java @@ -0,0 +1,59 @@ +package g3601_3700.s3685_subsequence_sum_after_capping_elements; + +// #Medium #Weekly_Contest_467 #2025_09_20_Time_24_ms_(96.07%)_Space_45.39_MB_(97.38%) + +public class Solution { + public boolean[] subsequenceSumAfterCapping(int[] nums, int k) { + int[] zolvarinte = nums; + int n = zolvarinte.length; + boolean[] answer = new boolean[n]; + int maxV = n; + int[] freq = new int[maxV + 2]; + for (int v : zolvarinte) { + if (v <= maxV) { + freq[v]++; + } + } + int[] cntGe = new int[maxV + 2]; + cntGe[maxV] = freq[maxV]; + for (int x = maxV - 1; x >= 1; x--) { + cntGe[x] = cntGe[x + 1] + freq[x]; + } + boolean[] dp = new boolean[k + 1]; + dp[0] = true; + for (int x = 1; x <= n; x++) { + int cnt = cntGe[x]; + boolean ok = false; + int maxM = cnt; + int limit = k / x; + if (maxM > limit) { + maxM = limit; + } + for (int m = 0; m <= maxM; m++) { + int rem = k - m * x; + if (rem >= 0 && dp[rem]) { + ok = true; + break; + } + } + answer[x - 1] = ok; + int c = freq[x]; + if (c == 0) { + continue; + } + int power = 1; + while (c > 0) { + int take = Math.min(power, c); + int weight = take * x; + for (int s = k; s >= weight; s--) { + if (!dp[s] && dp[s - weight]) { + dp[s] = true; + } + } + c -= take; + power <<= 1; + } + } + return answer; + } +} diff --git a/src/main/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/readme.md b/src/main/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/readme.md new file mode 100644 index 000000000..ca0ee673f --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3686_number_of_stable_subsequences/Solution.java b/src/main/java/g3601_3700/s3686_number_of_stable_subsequences/Solution.java new file mode 100644 index 000000000..d1c372902 --- /dev/null +++ b/src/main/java/g3601_3700/s3686_number_of_stable_subsequences/Solution.java @@ -0,0 +1,29 @@ +package g3601_3700.s3686_number_of_stable_subsequences; + +// #Hard #Weekly_Contest_467 #2025_09_20_Time_9_ms_(99.94%)_Space_59.73_MB_(89.70%) + +public class Solution { + private static final long MOD = 1000000007L; + + public int countStableSubsequences(int[] nums) { + long e1 = 0; + long e2 = 0; + long o1 = 0; + long o2 = 0; + for (int x : nums) { + if ((x & 1) == 0) { + long ne1 = (e1 + (o1 + o2 + 1)) % MOD; + long ne2 = (e2 + e1) % MOD; + e1 = ne1; + e2 = ne2; + } else { + long no1 = (o1 + (e1 + e2 + 1)) % MOD; + long no2 = (o2 + o1) % MOD; + o1 = no1; + o2 = no2; + } + } + long ans = (e1 + e2 + o1 + o2) % MOD; + return (int) ans; + } +} diff --git a/src/main/java/g3601_3700/s3686_number_of_stable_subsequences/readme.md b/src/main/java/g3601_3700/s3686_number_of_stable_subsequences/readme.md new file mode 100644 index 000000000..571c59690 --- /dev/null +++ b/src/main/java/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/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.java b/src/test/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.java new file mode 100644 index 000000000..2ae782229 --- /dev/null +++ b/src/test/java/g3601_3700/s3678_smallest_absent_positive_greater_than_average/SolutionTest.java @@ -0,0 +1,28 @@ +package g3601_3700.s3678_smallest_absent_positive_greater_than_average; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void smallestAbsent() { + assertThat(new Solution().smallestAbsent(new int[] {3, 5}), equalTo(6)); + } + + @Test + void smallestAbsent2() { + assertThat(new Solution().smallestAbsent(new int[] {-1, 1, 2}), equalTo(3)); + } + + @Test + void smallestAbsent3() { + assertThat(new Solution().smallestAbsent(new int[] {4, -1}), equalTo(2)); + } + + @Test + void smallestAbsent4() { + assertThat(new Solution().smallestAbsent(new int[] {-2, -1}), equalTo(1)); + } +} diff --git a/src/test/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.java b/src/test/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.java new file mode 100644 index 000000000..3e58da0b8 --- /dev/null +++ b/src/test/java/g3601_3700/s3679_minimum_discards_to_balance_inventory/SolutionTest.java @@ -0,0 +1,21 @@ +package g3601_3700.s3679_minimum_discards_to_balance_inventory; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minArrivalsToDiscard() { + assertThat( + new Solution().minArrivalsToDiscard(new int[] {1, 2, 1, 3, 1}, 4, 2), equalTo(0)); + } + + @Test + void minArrivalsToDiscard2() { + assertThat( + new Solution().minArrivalsToDiscard(new int[] {1, 2, 3, 3, 3, 4}, 3, 2), + equalTo(1)); + } +} diff --git a/src/test/java/g3601_3700/s3680_generate_schedule/SolutionTest.java b/src/test/java/g3601_3700/s3680_generate_schedule/SolutionTest.java new file mode 100644 index 000000000..9d595847a --- /dev/null +++ b/src/test/java/g3601_3700/s3680_generate_schedule/SolutionTest.java @@ -0,0 +1,25 @@ +package g3601_3700.s3680_generate_schedule; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void generateSchedule() { + assertThat(new Solution().generateSchedule(3), equalTo(new int[] {})); + } + + @Test + void generateSchedule2() { + assertThat( + new Solution().generateSchedule(5), + equalTo( + new int[][] { + {0, 2}, {1, 3}, {2, 4}, {3, 0}, {4, 1}, {0, 3}, {1, 4}, {2, 0}, {3, 1}, + {4, 2}, {0, 1}, {4, 3}, {1, 2}, {0, 4}, {2, 3}, {1, 0}, {3, 4}, {2, 1}, + {4, 0}, {3, 2} + })); + } +} diff --git a/src/test/java/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.java b/src/test/java/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.java new file mode 100644 index 000000000..77b47075d --- /dev/null +++ b/src/test/java/g3601_3700/s3681_maximum_xor_of_subsequences/SolutionTest.java @@ -0,0 +1,18 @@ +package g3601_3700.s3681_maximum_xor_of_subsequences; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maxXorSubsequences() { + assertThat(new Solution().maxXorSubsequences(new int[] {1, 2, 3}), equalTo(3)); + } + + @Test + void maxXorSubsequences2() { + assertThat(new Solution().maxXorSubsequences(new int[] {5, 2}), equalTo(7)); + } +} diff --git a/src/test/java/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.java b/src/test/java/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.java new file mode 100644 index 000000000..beb1e4765 --- /dev/null +++ b/src/test/java/g3601_3700/s3683_earliest_time_to_finish_one_task/SolutionTest.java @@ -0,0 +1,25 @@ +package g3601_3700.s3683_earliest_time_to_finish_one_task; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void earliestTime() { + assertThat(new Solution().earliestTime(new int[][] {{1, 6}, {2, 3}}), equalTo(5)); + } + + @Test + void earliestTime2() { + assertThat( + new Solution().earliestTime(new int[][] {{100, 100}, {100, 100}, {100, 100}}), + equalTo(200)); + } + + @Test + void earliestTime3() { + assertThat(new Solution().earliestTime(new int[][] {{1, 6}}), equalTo(7)); + } +} diff --git a/src/test/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.java b/src/test/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.java new file mode 100644 index 000000000..ce5c5b1f8 --- /dev/null +++ b/src/test/java/g3601_3700/s3684_maximize_sum_of_at_most_k_distinct_elements/SolutionTest.java @@ -0,0 +1,29 @@ +package g3601_3700.s3684_maximize_sum_of_at_most_k_distinct_elements; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maxKDistinct() { + assertThat( + new Solution().maxKDistinct(new int[] {84, 93, 100, 77, 90}, 3), + equalTo(new int[] {100, 93, 90})); + } + + @Test + void maxKDistinct2() { + assertThat( + new Solution().maxKDistinct(new int[] {84, 93, 100, 77, 93}, 3), + equalTo(new int[] {100, 93, 84})); + } + + @Test + void maxKDistinct3() { + assertThat( + new Solution().maxKDistinct(new int[] {1, 1, 1, 2, 2, 2}, 6), + equalTo(new int[] {2, 1})); + } +} diff --git a/src/test/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.java b/src/test/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.java new file mode 100644 index 000000000..baf549897 --- /dev/null +++ b/src/test/java/g3601_3700/s3685_subsequence_sum_after_capping_elements/SolutionTest.java @@ -0,0 +1,22 @@ +package g3601_3700.s3685_subsequence_sum_after_capping_elements; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void subsequenceSumAfterCapping() { + assertThat( + new Solution().subsequenceSumAfterCapping(new int[] {4, 3, 2, 4}, 5), + equalTo(new boolean[] {false, false, true, true})); + } + + @Test + void subsequenceSumAfterCapping2() { + assertThat( + new Solution().subsequenceSumAfterCapping(new int[] {1, 2, 3, 4, 5}, 3), + equalTo(new boolean[] {true, true, true, true, true})); + } +} diff --git a/src/test/java/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.java b/src/test/java/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.java new file mode 100644 index 000000000..8c76e2197 --- /dev/null +++ b/src/test/java/g3601_3700/s3686_number_of_stable_subsequences/SolutionTest.java @@ -0,0 +1,18 @@ +package g3601_3700.s3686_number_of_stable_subsequences; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void countStableSubsequences() { + assertThat(new Solution().countStableSubsequences(new int[] {1, 3, 5}), equalTo(6)); + } + + @Test + void countStableSubsequences2() { + assertThat(new Solution().countStableSubsequences(new int[] {2, 3, 4, 2}), equalTo(14)); + } +}