diff --git a/src/main/java/g3601_3700/s3657_find_loyal_customers/readme.md b/src/main/java/g3601_3700/s3657_find_loyal_customers/readme.md new file mode 100644 index 000000000..909e6c5da --- /dev/null +++ b/src/main/java/g3601_3700/s3657_find_loyal_customers/readme.md @@ -0,0 +1,93 @@ +3657\. Find Loyal Customers + +Medium + +Table: `customer_transactions` + + +------------------+---------+ + | Column Name | Type | + +------------------+---------+ + | transaction_id | int | + | customer_id | int | + | transaction_date | date | + | amount | decimal | + | transaction_type | varchar | + +------------------+---------+ + transaction_id is the unique identifier for this table. transaction_type can be either 'purchase' or 'refund'. + +Write a solution to find **loyal customers**. A customer is considered **loyal** if they meet ALL the following criteria: + +* Made **at least** `3` purchase transactions. +* Have been active for **at least** `30` days. +* Their **refund rate** is less than `20%` . + +Return _the result table ordered by_ `customer_id` _in **ascending** order_. + +The result format is in the following example. + +**Example:** + +**Input:** + +customer\_transactions table: + + +----------------+-------------+------------------+--------+------------------+ + | transaction_id | customer_id | transaction_date | amount | transaction_type | + |----------------|-------------|------------------|--------|------------------| + | 1 | 101 | 2024-01-05 | 150.00 | purchase | + | 2 | 101 | 2024-01-15 | 200.00 | purchase | + | 3 | 101 | 2024-02-10 | 180.00 | purchase | + | 4 | 101 | 2024-02-20 | 250.00 | purchase | + | 5 | 102 | 2024-01-10 | 100.00 | purchase | + | 6 | 102 | 2024-01-12 | 120.00 | purchase | + | 7 | 102 | 2024-01-15 | 80.00 | refund | + | 8 | 102 | 2024-01-18 | 90.00 | refund | + | 9 | 102 | 2024-02-15 | 130.00 | purchase | + | 10 | 103 | 2024-01-01 | 500.00 | purchase | + | 11 | 103 | 2024-01-02 | 450.00 | purchase | + | 12 | 103 | 2024-01-03 | 400.00 | purchase | + | 13 | 104 | 2024-01-01 | 200.00 | purchase | + | 14 | 104 | 2024-02-01 | 250.00 | purchase | + | 15 | 104 | 2024-02-15 | 300.00 | purchase | + | 16 | 104 | 2024-03-01 | 350.00 | purchase | + | 17 | 104 | 2024-03-10 | 280.00 | purchase | + | 18 | 104 | 2024-03-15 | 100.00 | refund | + +----------------+-------------+------------------+--------+------------------+ + + +**Output:** + + +-------------+ + | customer_id | + |-------------| + | 101 | + | 104 | + +-------------+ + +**Explanation:** + +* **Customer 101**: + * Purchase transactions: 4 (IDs: 1, 2, 3, 4) + * Refund transactions: 0 + * Refund rate: 0/4 = 0% (less than 20%) + * Active period: Jan 5 to Feb 20 = 46 days (at least 30 days) + * Qualifies as loyal +* **Customer 102**: + * Purchase transactions: 3 (IDs: 5, 6, 9) + * Refund transactions: 2 (IDs: 7, 8) + * Refund rate: 2/5 = 40% (exceeds 20%) + * Not loyal +* **Customer 103**: + * Purchase transactions: 3 (IDs: 10, 11, 12) + * Refund transactions: 0 + * Refund rate: 0/3 = 0% (less than 20%) + * Active period: Jan 1 to Jan 3 = 2 days (less than 30 days) + * Not loyal +* **Customer 104**: + * Purchase transactions: 5 (IDs: 13, 14, 15, 16, 17) + * Refund transactions: 1 (ID: 18) + * Refund rate: 1/6 = 16.67% (less than 20%) + * Active period: Jan 1 to Mar 15 = 73 days (at least 30 days) + * Qualifies as loyal + +The result table is ordered by customer\_id in ascending order. \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3657_find_loyal_customers/script.sql b/src/main/java/g3601_3700/s3657_find_loyal_customers/script.sql new file mode 100644 index 000000000..61c9ec2ca --- /dev/null +++ b/src/main/java/g3601_3700/s3657_find_loyal_customers/script.sql @@ -0,0 +1,14 @@ +# Write your MySQL query statement below +# #Medium #Database #2025_08_25_Time_297_ms_(100.00%)_Space_0.0_MB_(100.00%) +SELECT + customer_id +FROM + customer_transactions +GROUP BY + customer_id +HAVING + COUNT(CASE WHEN transaction_type = 'purchase' THEN 1 END) > 2 + AND TIMESTAMPDIFF(DAY, MIN(transaction_date), MAX(transaction_date)) > 29 + AND (COUNT(CASE WHEN transaction_type = 'refund' THEN 1 END) * 1.0 / COUNT(*)) < 0.2 +ORDER BY + customer_id ASC; diff --git a/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/Solution.java b/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/Solution.java new file mode 100644 index 000000000..4c4d66b00 --- /dev/null +++ b/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/Solution.java @@ -0,0 +1,9 @@ +package g3601_3700.s3658_gcd_of_odd_and_even_sums; + +// #Easy #Weekly_Contest_464 #2025_08_24_Time_1_ms_(100.00%)_Space_41.16_MB_(100.00%) + +public class Solution { + public int gcdOfOddEvenSums(int n) { + return (n < 0) ? -n : n; + } +} diff --git a/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/readme.md b/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/readme.md new file mode 100644 index 000000000..b5871abf8 --- /dev/null +++ b/src/main/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/readme.md @@ -0,0 +1,42 @@ +3658\. GCD of Odd and Even Sums + +Easy + +You are given an integer `n`. Your task is to compute the **GCD** (greatest common divisor) of two values: + +* `sumOdd`: the sum of the first `n` odd numbers. + +* `sumEven`: the sum of the first `n` even numbers. + + +Return the GCD of `sumOdd` and `sumEven`. + +**Example 1:** + +**Input:** n = 4 + +**Output:** 4 + +**Explanation:** + +* Sum of the first 4 odd numbers `sumOdd = 1 + 3 + 5 + 7 = 16` +* Sum of the first 4 even numbers `sumEven = 2 + 4 + 6 + 8 = 20` + +Hence, `GCD(sumOdd, sumEven) = GCD(16, 20) = 4`. + +**Example 2:** + +**Input:** n = 5 + +**Output:** 5 + +**Explanation:** + +* Sum of the first 5 odd numbers `sumOdd = 1 + 3 + 5 + 7 + 9 = 25` +* Sum of the first 5 even numbers `sumEven = 2 + 4 + 6 + 8 + 10 = 30` + +Hence, `GCD(sumOdd, sumEven) = GCD(25, 30) = 5`. + +**Constraints:** + +* `1 <= n <= 1000` \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/Solution.java b/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/Solution.java new file mode 100644 index 000000000..4291d24e1 --- /dev/null +++ b/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/Solution.java @@ -0,0 +1,20 @@ +package g3601_3700.s3659_partition_array_into_k_distinct_groups; + +// #Medium #Weekly_Contest_464 #2025_08_24_Time_81_ms_(100.00%)_Space_62.78_MB_(100.00%) + +import java.util.HashMap; + +public class Solution { + public boolean partitionArray(int[] nums, int k) { + HashMap mpp = new HashMap<>(); + for (int x : nums) { + mpp.put(x, mpp.getOrDefault(x, 0) + 1); + } + for (int count : mpp.values()) { + if (count > nums.length / k) { + return false; + } + } + return nums.length % k == 0; + } +} diff --git a/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/readme.md b/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/readme.md new file mode 100644 index 000000000..88154c062 --- /dev/null +++ b/src/main/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/readme.md @@ -0,0 +1,58 @@ +3659\. Partition Array Into K-Distinct Groups + +Medium + +You are given an integer array `nums` and an integer `k`. + +Your task is to determine whether it is possible to partition all elements of `nums` into one or more groups such that: + +* Each group contains **exactly** `k` **distinct** elements. +* Each element in `nums` must be assigned to **exactly** one group. + +Return `true` if such a partition is possible, otherwise return `false`. + +**Example 1:** + +**Input:** nums = [1,2,3,4], k = 2 + +**Output:** true + +**Explanation:** + +One possible partition is to have 2 groups: + +* Group 1: `[1, 2]` +* Group 2: `[3, 4]` + +Each group contains `k = 2` distinct elements, and all elements are used exactly once. + +**Example 2:** + +**Input:** nums = [3,5,2,2], k = 2 + +**Output:** true + +**Explanation:** + +One possible partition is to have 2 groups: + +* Group 1: `[2, 3]` +* Group 2: `[2, 5]` + +Each group contains `k = 2` distinct elements, and all elements are used exactly once. + +**Example 3:** + +**Input:** nums = [1,5,2,3], k = 3 + +**Output:** false + +**Explanation:** + +We cannot form groups of `k = 3` distinct elements using all values exactly once. + +**Constraints:** + +* 1 <= nums.length <= 105 +* 1 <= nums[i] <= 105 +* `1 <= k <= nums.length` \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3660_jump_game_ix/Solution.java b/src/main/java/g3601_3700/s3660_jump_game_ix/Solution.java new file mode 100644 index 000000000..1cbcf5e8e --- /dev/null +++ b/src/main/java/g3601_3700/s3660_jump_game_ix/Solution.java @@ -0,0 +1,89 @@ +package g3601_3700.s3660_jump_game_ix; + +// #Medium #Weekly_Contest_464 #2025_08_24_Time_248_ms_(100.00%)_Space_72.98_MB_(100.00%) + +import java.util.ArrayDeque; +import java.util.HashMap; + +public class Solution { + public int[] maxValue(int[] nums) { + int n = nums.length; + ArrayDeque st = new ArrayDeque<>(); + UnionFind uf = new UnionFind(n); + for (int i = 0; i < n; i++) { + int prev = i; + if (!st.isEmpty()) { + prev = st.peek(); + } + while (!st.isEmpty() && nums[i] < nums[st.peek()]) { + uf.union(st.pop(), i); + } + if (nums[i] > nums[prev]) { + st.push(i); + } else { + st.push(prev); + } + } + st.clear(); + for (int i = n - 1; i >= 0; i--) { + int prev = i; + if (!st.isEmpty()) { + prev = st.peek(); + } + while (!st.isEmpty() && nums[i] > nums[st.peek()]) { + uf.union(st.pop(), i); + } + if (nums[i] < nums[prev]) { + st.push(i); + } else { + st.push(prev); + } + } + HashMap map = new HashMap<>(); + for (int i = 0; i < n; i++) { + int root = uf.find(i); + map.put(root, Math.max(map.getOrDefault(root, Integer.MIN_VALUE), nums[i])); + } + int[] ans = new int[n]; + for (int i = 0; i < n; i++) { + ans[i] = map.get(uf.find(i)); + } + return ans; + } + + private static class UnionFind { + int[] par; + int[] rank; + + UnionFind(int n) { + par = new int[n]; + rank = new int[n]; + for (int i = 0; i < n; i++) { + par[i] = i; + } + } + + int find(int x) { + if (par[x] != x) { + par[x] = find(par[x]); + } + return par[x]; + } + + void union(int x, int y) { + x = find(x); + y = find(y); + if (x == y) { + return; + } + if (rank[x] < rank[y]) { + par[x] = y; + } else if (rank[x] > rank[y]) { + par[y] = x; + } else { + par[y] = x; + rank[x]++; + } + } + } +} diff --git a/src/main/java/g3601_3700/s3660_jump_game_ix/readme.md b/src/main/java/g3601_3700/s3660_jump_game_ix/readme.md new file mode 100644 index 000000000..413da21f4 --- /dev/null +++ b/src/main/java/g3601_3700/s3660_jump_game_ix/readme.md @@ -0,0 +1,47 @@ +3660\. Jump Game IX + +Medium + +You are given an integer array `nums`. + +From any index `i`, you can jump to another index `j` under the following rules: + +* Jump to index `j` where `j > i` is allowed only if `nums[j] < nums[i]`. +* Jump to index `j` where `j < i` is allowed only if `nums[j] > nums[i]`. + +For each index `i`, find the **maximum** **value** in `nums` that can be reached by following **any** sequence of valid jumps starting at `i`. + +Return an array `ans` where `ans[i]` is the **maximum** **value** reachable starting from index `i`. + +**Example 1:** + +**Input:** nums = [2,1,3] + +**Output:** [2,2,3] + +**Explanation:** + +* For `i = 0`: No jump increases the value. +* For `i = 1`: Jump to `j = 0` as `nums[j] = 2` is greater than `nums[i]`. +* For `i = 2`: Since `nums[2] = 3` is the maximum value in `nums`, no jump increases the value. + +Thus, `ans = [2, 2, 3]`. + +**Example 2:** + +**Input:** nums = [2,3,1] + +**Output:** [3,3,3] + +**Explanation:** + +* For `i = 0`: Jump forward to `j = 2` as `nums[j] = 1` is less than `nums[i] = 2`, then from `i = 2` jump to `j = 1` as `nums[j] = 3` is greater than `nums[2]`. +* For `i = 1`: Since `nums[1] = 3` is the maximum value in `nums`, no jump increases the value. +* For `i = 2`: Jump to `j = 1` as `nums[j] = 3` is greater than `nums[2] = 1`. + +Thus, `ans = [3, 3, 3]`. + +**Constraints:** + +* 1 <= nums.length <= 105 +* 1 <= nums[i] <= 109 \ No newline at end of file diff --git a/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/Solution.java b/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/Solution.java new file mode 100644 index 000000000..34c9cda10 --- /dev/null +++ b/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/Solution.java @@ -0,0 +1,120 @@ +package g3601_3700.s3661_maximum_walls_destroyed_by_robots; + +// #Hard #Weekly_Contest_464 #2025_08_24_Time_164_ms_(100.00%)_Space_59.97_MB_(100.00%) + +import java.util.Arrays; + +public class Solution { + public int maxWalls(int[] robots, int[] distance, int[] walls) { + int n = robots.length; + // Pair robots with distances and sort + int[][] rpair = new int[n][2]; + for (int i = 0; i < n; i++) { + rpair[i][0] = robots[i]; + rpair[i][1] = distance[i]; + } + Arrays.sort(rpair, (a, b) -> Integer.compare(a[0], b[0])); + int[] r = new int[n]; + int[] d = new int[n]; + for (int i = 0; i < n; i++) { + r[i] = rpair[i][0]; + d[i] = rpair[i][1]; + } + Arrays.sort(walls); + // Count walls at robot positions + int base = 0; + for (int i = 0; i < n; i++) { + int idx = Arrays.binarySearch(walls, r[i]); + if (idx >= 0) { + base++; + } + } + // Tail walls + int leftTail = countRange(walls, (long) r[0] - d[0], r[0] - 1L); + int rightTail = countRange(walls, r[n - 1] + 1L, (long) r[n - 1] + d[n - 1]); + // Precompute segment ranges + int segs = n - 1; + int max = Math.max(0, segs); + int[] a = new int[max]; + int[] b = new int[max]; + int[] c = new int[max]; + for (int i = 0; i < segs; i++) { + int segL = r[i] + 1; + int segR = r[i + 1] - 1; + if (segL > segR) { + a[i] = b[i] = c[i] = 0; + continue; + } + int aHigh = Math.min(segR, r[i] + d[i]); + a[i] = countRange(walls, segL, aHigh); + int bLow = Math.max(segL, r[i + 1] - d[i + 1]); + b[i] = countRange(walls, bLow, segR); + int cLow = Math.max(segL, r[i + 1] - d[i + 1]); + int cHigh = Math.min(segR, r[i] + d[i]); + c[i] = countRange(walls, cLow, cHigh); + } + int[][] dp = new int[n][2]; + Arrays.fill(dp[0], Integer.MIN_VALUE / 4); + // first fires left + dp[0][0] = base + leftTail; + // first fires right + dp[0][1] = base; + for (int i = 0; i < n - 1; i++) { + Arrays.fill(dp[i + 1], Integer.MIN_VALUE / 4); + for (int choice = 0; choice <= 1; choice++) { + int cur = dp[i][choice]; + if (cur < 0) { + continue; + } + int addIfNextLeft = (choice == 1) ? a[i] + b[i] - c[i] : b[i]; + dp[i + 1][0] = Math.max(dp[i + 1][0], cur + addIfNextLeft); + int addIfNextRight = (choice == 1) ? a[i] : 0; + dp[i + 1][1] = Math.max(dp[i + 1][1], cur + addIfNextRight); + } + } + int res; + if (n == 1) { + res = Math.max(dp[0][0], dp[0][1] + rightTail); + } else { + res = Math.max(dp[n - 1][0], dp[n - 1][1] + rightTail); + } + return res; + } + + private int countRange(int[] arr, long l, long r) { + if (l > r || arr.length == 0) { + return 0; + } + int leftIdx = lowerBound(arr, l); + int rightIdx = upperBound(arr, r); + return Math.max(0, rightIdx - leftIdx); + } + + private int lowerBound(int[] a, long x) { + int l = 0; + int r = a.length; + while (l < r) { + int m = (l + r) >>> 1; + if (a[m] < x) { + l = m + 1; + } else { + r = m; + } + } + return l; + } + + private int upperBound(int[] a, long x) { + int l = 0; + int r = a.length; + while (l < r) { + int m = (l + r) >>> 1; + if (a[m] <= x) { + l = m + 1; + } else { + r = m; + } + } + return l; + } +} diff --git a/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/readme.md b/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/readme.md new file mode 100644 index 000000000..743dbad2a --- /dev/null +++ b/src/main/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/readme.md @@ -0,0 +1,62 @@ +3661\. Maximum Walls Destroyed by Robots + +Hard + +There is an endless straight line populated with some robots and walls. You are given integer arrays `robots`, `distance`, and `walls`: + +* `robots[i]` is the position of the ith robot. +* `distance[i]` is the **maximum** distance the ith robot's bullet can travel. +* `walls[j]` is the position of the jth wall. + +Every robot has **one** bullet that can either fire to the left or the right **at most** `distance[i]` meters. + +A bullet destroys every wall in its path that lies within its range. Robots are fixed obstacles: if a bullet hits another robot before reaching a wall, it **immediately stops** at that robot and cannot continue. + +Return the **maximum** number of **unique** walls that can be destroyed by the robots. + +Notes: + +* A wall and a robot may share the same position; the wall can be destroyed by the robot at that position. +* Robots are not destroyed by bullets. + +**Example 1:** + +**Input:** robots = [4], distance = [3], walls = [1,10] + +**Output:** 1 + +**Explanation:** + +* `robots[0] = 4` fires **left** with `distance[0] = 3`, covering `[1, 4]` and destroys `walls[0] = 1`. +* Thus, the answer is 1. + +**Example 2:** + +**Input:** robots = [10,2], distance = [5,1], walls = [5,2,7] + +**Output:** 3 + +**Explanation:** + +* `robots[0] = 10` fires **left** with `distance[0] = 5`, covering `[5, 10]` and destroys `walls[0] = 5` and `walls[2] = 7`. +* `robots[1] = 2` fires **left** with `distance[1] = 1`, covering `[1, 2]` and destroys `walls[1] = 2`. +* Thus, the answer is 3. + +**Example 3:** + +**Input:** robots = [1,2], distance = [100,1], walls = [10] + +**Output:** 0 + +**Explanation:** + +In this example, only `robots[0]` can reach the wall, but its shot to the **right** is blocked by `robots[1]`; thus the answer is 0. + +**Constraints:** + +* 1 <= robots.length == distance.length <= 105 +* 1 <= walls.length <= 105 +* 1 <= robots[i], walls[j] <= 109 +* 1 <= distance[i] <= 105 +* All values in `robots` are **unique** +* All values in `walls` are **unique** \ No newline at end of file diff --git a/src/test/java/g3601_3700/s3657_find_loyal_customers/MysqlTest.java b/src/test/java/g3601_3700/s3657_find_loyal_customers/MysqlTest.java new file mode 100644 index 000000000..22a5ae720 --- /dev/null +++ b/src/test/java/g3601_3700/s3657_find_loyal_customers/MysqlTest.java @@ -0,0 +1,75 @@ +package g3601_3700.s3657_find_loyal_customers; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.stream.Collectors; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.zapodot.junit.db.annotations.EmbeddedDatabase; +import org.zapodot.junit.db.annotations.EmbeddedDatabaseTest; +import org.zapodot.junit.db.common.CompatibilityMode; + +@EmbeddedDatabaseTest( + compatibilityMode = CompatibilityMode.MySQL, + initialSqls = + "CREATE TABLE customer_transactions (" + + " transaction_id INT PRIMARY KEY," + + " customer_id INT NOT NULL," + + " transaction_date DATE NOT NULL," + + " amount DECIMAL(10,2) NOT NULL," + + " transaction_type ENUM('purchase', 'refund') NOT NULL" + + ");" + + "INSERT INTO customer_transactions" + + "(transaction_id, customer_id, transaction_date, amount, transaction_type)" + + "VALUES" + + "(1, 101, '2024-01-05', 150.00, 'purchase')," + + "(2, 101, '2024-01-15', 200.00, 'purchase')," + + "(3, 101, '2024-02-10', 180.00, 'purchase')," + + "(4, 101, '2024-02-20', 250.00, 'purchase')," + + "(5, 102, '2024-01-10', 100.00, 'purchase')," + + "(6, 102, '2024-01-12', 120.00, 'purchase')," + + "(7, 102, '2024-01-15', 80.00, 'refund')," + + "(8, 102, '2024-01-18', 90.00, 'refund')," + + "(9, 102, '2024-02-15', 130.00, 'purchase')," + + "(10, 103, '2024-01-01', 500.00, 'purchase')," + + "(11, 103, '2024-01-02', 450.00, 'purchase')," + + "(12, 103, '2024-01-03', 400.00, 'purchase')," + + "(13, 104, '2024-01-01', 200.00, 'purchase')," + + "(14, 104, '2024-02-01', 250.00, 'purchase')," + + "(15, 104, '2024-02-15', 300.00, 'purchase')," + + "(16, 104, '2024-03-01', 350.00, 'purchase')," + + "(17, 104, '2024-03-10', 280.00, 'purchase')," + + "(18, 104, '2024-03-15', 100.00, 'refund');") +class MysqlTest { + @Test + void testScript(@EmbeddedDatabase DataSource dataSource) + throws SQLException, FileNotFoundException { + try (final Connection connection = dataSource.getConnection()) { + try (final Statement statement = connection.createStatement(); + final ResultSet resultSet = + statement.executeQuery( + new BufferedReader( + new FileReader( + "src/main/java/g3601_3700/" + + "s3657_find_loyal_customers/" + + "script.sql")) + .lines() + .collect(Collectors.joining("\n")) + .replaceAll("#.*?\\r?\\n", ""))) { + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("101")); + assertThat(resultSet.next(), equalTo(true)); + assertThat(resultSet.getNString(1), equalTo("104")); + assertThat(resultSet.next(), equalTo(false)); + } + } + } +} diff --git a/src/test/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/SolutionTest.java b/src/test/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/SolutionTest.java new file mode 100644 index 000000000..fe504bbc0 --- /dev/null +++ b/src/test/java/g3601_3700/s3658_gcd_of_odd_and_even_sums/SolutionTest.java @@ -0,0 +1,18 @@ +package g3601_3700.s3658_gcd_of_odd_and_even_sums; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void gcdOfOddEvenSums() { + assertThat(new Solution().gcdOfOddEvenSums(4), equalTo(4)); + } + + @Test + void gcdOfOddEvenSums2() { + assertThat(new Solution().gcdOfOddEvenSums(5), equalTo(5)); + } +} diff --git a/src/test/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/SolutionTest.java b/src/test/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/SolutionTest.java new file mode 100644 index 000000000..b053fc038 --- /dev/null +++ b/src/test/java/g3601_3700/s3659_partition_array_into_k_distinct_groups/SolutionTest.java @@ -0,0 +1,23 @@ +package g3601_3700.s3659_partition_array_into_k_distinct_groups; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void partitionArray() { + assertThat(new Solution().partitionArray(new int[] {1, 2, 3, 4}, 2), equalTo(true)); + } + + @Test + void partitionArray2() { + assertThat(new Solution().partitionArray(new int[] {3, 5, 2, 2}, 2), equalTo(true)); + } + + @Test + void partitionArray3() { + assertThat(new Solution().partitionArray(new int[] {1, 5, 2, 3}, 3), equalTo(false)); + } +} diff --git a/src/test/java/g3601_3700/s3660_jump_game_ix/SolutionTest.java b/src/test/java/g3601_3700/s3660_jump_game_ix/SolutionTest.java new file mode 100644 index 000000000..3ce65d390 --- /dev/null +++ b/src/test/java/g3601_3700/s3660_jump_game_ix/SolutionTest.java @@ -0,0 +1,18 @@ +package g3601_3700.s3660_jump_game_ix; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maxValue() { + assertThat(new Solution().maxValue(new int[] {2, 1, 3}), equalTo(new int[] {2, 2, 3})); + } + + @Test + void maxValue2() { + assertThat(new Solution().maxValue(new int[] {2, 3, 1}), equalTo(new int[] {3, 3, 3})); + } +} diff --git a/src/test/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/SolutionTest.java b/src/test/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/SolutionTest.java new file mode 100644 index 000000000..12a23fce6 --- /dev/null +++ b/src/test/java/g3601_3700/s3661_maximum_walls_destroyed_by_robots/SolutionTest.java @@ -0,0 +1,29 @@ +package g3601_3700.s3661_maximum_walls_destroyed_by_robots; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maxWalls() { + assertThat( + new Solution().maxWalls(new int[] {4}, new int[] {3}, new int[] {1, 10}), + equalTo(1)); + } + + @Test + void maxWalls2() { + assertThat( + new Solution().maxWalls(new int[] {10, 2}, new int[] {5, 1}, new int[] {5, 2, 7}), + equalTo(3)); + } + + @Test + void maxWalls3() { + assertThat( + new Solution().maxWalls(new int[] {1, 2}, new int[] {100, 1}, new int[] {10}), + equalTo(0)); + } +}