diff --git a/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.java b/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.java new file mode 100644 index 000000000..28856d812 --- /dev/null +++ b/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.java @@ -0,0 +1,77 @@ +package g3001_3100.s3076_shortest_uncommon_substring_in_an_array; + +// #Medium #Array #String #Hash_Table #Trie #2024_04_16_Time_9_ms_(99.97%)_Space_45.8_MB_(39.57%) + +public class Solution { + private final Trie root = new Trie(); + + public String[] shortestSubstrings(String[] arr) { + int n = arr.length; + for (int k = 0; k < n; ++k) { + String s = arr[k]; + char[] cs = s.toCharArray(); + int m = cs.length; + for (int i = 0; i < m; ++i) { + insert(cs, i, m, k); + } + } + String[] ans = new String[n]; + for (int k = 0; k < n; ++k) { + String s = arr[k]; + char[] cs = s.toCharArray(); + int m = cs.length; + String result = ""; + int resultLen = m + 1; + for (int i = 0; i < m; ++i) { + int curLen = search(cs, i, Math.min(m, i + resultLen), k); + if (curLen != -1) { + String sub = new String(cs, i, curLen); + if (curLen < resultLen || result.compareTo(sub) > 0) { + result = sub; + resultLen = curLen; + } + } + } + ans[k] = result; + } + return ans; + } + + private void insert(char[] cs, int start, int end, int wordIndex) { + Trie curr = root; + for (int i = start; i < end; ++i) { + int index = cs[i] - 'a'; + if (curr.children[index] == null) { + curr.children[index] = new Trie(); + } + curr = curr.children[index]; + if (curr.wordIndex == -1 || curr.wordIndex == wordIndex) { + curr.wordIndex = wordIndex; + } else { + curr.wordIndex = -2; + } + } + } + + private int search(char[] cs, int start, int end, int wordIndex) { + Trie cur = root; + for (int i = start; i < end; i++) { + int index = cs[i] - 'a'; + cur = cur.children[index]; + if (cur.wordIndex == wordIndex) { + return i - start + 1; + } + } + return -1; + } + + private static class Trie { + Trie[] children; + int wordIndex; + + public Trie() { + children = new Trie[26]; + wordIndex = -1; + } + } +} diff --git a/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/readme.md b/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/readme.md new file mode 100644 index 000000000..f0c5b481c --- /dev/null +++ b/src/main/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/readme.md @@ -0,0 +1,41 @@ +3076\. Shortest Uncommon Substring in an Array + +Medium + +You are given an array `arr` of size `n` consisting of **non-empty** strings. + +Find a string array `answer` of size `n` such that: + +* `answer[i]` is the **shortest** substring of `arr[i]` that does **not** occur as a substring in any other string in `arr`. If multiple such substrings exist, `answer[i]` should be the lexicographically smallest. And if no such substring exists, `answer[i]` should be an empty string. + +Return _the array_ `answer`. + +**Example 1:** + +**Input:** arr = ["cab","ad","bad","c"] + +**Output:** ["ab","","ba",""] + +**Explanation:** We have the following: +- For the string "cab", the shortest substring that does not occur in any other string is either "ca" or "ab", we choose the lexicographically smaller substring, which is "ab". +- For the string "ad", there is no substring that does not occur in any other string. +- For the string "bad", the shortest substring that does not occur in any other string is "ba". +- For the string "c", there is no substring that does not occur in any other string. + +**Example 2:** + +**Input:** arr = ["abc","bcd","abcd"] + +**Output:** ["","","abcd"] + +**Explanation:** We have the following: +- For the string "abc", there is no substring that does not occur in any other string. +- For the string "bcd", there is no substring that does not occur in any other string. +- For the string "abcd", the shortest substring that does not occur in any other string is "abcd". + +**Constraints:** + +* `n == arr.length` +* `2 <= n <= 100` +* `1 <= arr[i].length <= 20` +* `arr[i]` consists only of lowercase English letters. \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/Solution.java b/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/Solution.java new file mode 100644 index 000000000..c64ccdaac --- /dev/null +++ b/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/Solution.java @@ -0,0 +1,36 @@ +package g3001_3100.s3077_maximum_strength_of_k_disjoint_subarrays; + +// #Hard #Array #Dynamic_Programming #Prefix_Sum +// #2024_04_16_Time_20_ms_(97.16%)_Space_56.3_MB_(71.00%) + +public class Solution { + public long maximumStrength(int[] n, int k) { + if (n.length == 1) { + return n[0]; + } + long[][] dp = new long[n.length][k]; + dp[0][0] = (long) k * n[0]; + for (int i = 1; i < k; i++) { + long pm = -1; + dp[i][0] = Math.max(0L, dp[i - 1][0]) + (long) k * n[i]; + for (int j = 1; j < i; j++) { + dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1]) + ((long) k - j) * n[i] * pm; + pm = -pm; + } + dp[i][i] = dp[i - 1][i - 1] + ((long) k - i) * n[i] * pm; + } + long max = dp[k - 1][k - 1]; + for (int i = k; i < n.length; i++) { + long pm = 1; + dp[i][0] = Math.max(0L, dp[i - 1][0]) + (long) k * n[i]; + for (int j = 1; j < k; j++) { + pm = -pm; + dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1]) + ((long) k - j) * n[i] * pm; + } + if (max < dp[i][k - 1]) { + max = dp[i][k - 1]; + } + } + return max; + } +} diff --git a/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/readme.md b/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/readme.md new file mode 100644 index 000000000..ded7a7f3e --- /dev/null +++ b/src/main/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/readme.md @@ -0,0 +1,45 @@ +3077\. Maximum Strength of K Disjoint Subarrays + +Hard + +You are given a **0-indexed** array of integers `nums` of length `n`, and a **positive** **odd** integer `k`. + +The strength of `x` subarrays is defined as `strength = sum[1] * x - sum[2] * (x - 1) + sum[3] * (x - 2) - sum[4] * (x - 3) + ... + sum[x] * 1` where `sum[i]` is the sum of the elements in the ith subarray. Formally, strength is sum of (-1)i+1 * sum[i] * (x - i + 1) over all `i`'s such that `1 <= i <= x`. + +You need to select `k` **disjoint subarrays** from `nums`, such that their **strength** is **maximum**. + +Return _the **maximum** possible **strength** that can be obtained_. + +**Note** that the selected subarrays **don't** need to cover the entire array. + +**Example 1:** + +**Input:** nums = [1,2,3,-1,2], k = 3 + +**Output:** 22 + +**Explanation:** The best possible way to select 3 subarrays is: nums[0..2], nums[3..3], and nums[4..4]. The strength is (1 + 2 + 3) \* 3 - (-1) \* 2 + 2 \* 1 = 22. + +**Example 2:** + +**Input:** nums = [12,-2,-2,-2,-2], k = 5 + +**Output:** 64 + +**Explanation:** The only possible way to select 5 disjoint subarrays is: nums[0..0], nums[1..1], nums[2..2], nums[3..3], and nums[4..4]. The strength is 12 \* 5 - (-2) \* 4 + (-2) \* 3 - (-2) \* 2 + (-2) \* 1 = 64. + +**Example 3:** + +**Input:** nums = [-1,-2,-3], k = 1 + +**Output:** -1 + +**Explanation:** The best possible way to select 1 subarray is: nums[0..0]. The strength is -1. + +**Constraints:** + +* 1 <= n <= 104 +* -109 <= nums[i] <= 109 +* `1 <= k <= n` +* 1 <= n * k <= 106 +* `k` is odd. \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/Solution.java b/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/Solution.java new file mode 100644 index 000000000..1f86069f7 --- /dev/null +++ b/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/Solution.java @@ -0,0 +1,28 @@ +package g3001_3100.s3079_find_the_sum_of_encrypted_integers; + +// #Easy #Array #Math #2024_04_16_Time_1_ms_(99.95%)_Space_42.7_MB_(75.97%) + +public class Solution { + private int encrypt(int x) { + int nDigits = 0; + int max = 0; + while (x > 0) { + max = Math.max(max, x % 10); + x /= 10; + nDigits++; + } + int ans = 0; + for (int i = 0; i < nDigits; i++) { + ans = ans * 10 + max; + } + return ans; + } + + public int sumOfEncryptedInt(int[] nums) { + int ret = 0; + for (int num : nums) { + ret += encrypt(num); + } + return ret; + } +} diff --git a/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/readme.md b/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/readme.md new file mode 100644 index 000000000..369fcc981 --- /dev/null +++ b/src/main/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/readme.md @@ -0,0 +1,28 @@ +3079\. Find the Sum of Encrypted Integers + +Easy + +You are given an integer array `nums` containing **positive** integers. We define a function `encrypt` such that `encrypt(x)` replaces **every** digit in `x` with the **largest** digit in `x`. For example, `encrypt(523) = 555` and `encrypt(213) = 333`. + +Return _the **sum** of encrypted elements_. + +**Example 1:** + +**Input:** nums = [1,2,3] + +**Output:** 6 + +**Explanation:** The encrypted elements are `[1,2,3]`. The sum of encrypted elements is `1 + 2 + 3 == 6`. + +**Example 2:** + +**Input:** nums = [10,21,31] + +**Output:** 66 + +**Explanation:** The encrypted elements are `[11,22,33]`. The sum of encrypted elements is `11 + 22 + 33 == 66`. + +**Constraints:** + +* `1 <= nums.length <= 50` +* `1 <= nums[i] <= 1000` \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/Solution.java b/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/Solution.java new file mode 100644 index 000000000..1f0020a62 --- /dev/null +++ b/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/Solution.java @@ -0,0 +1,85 @@ +package g3001_3100.s3080_mark_elements_on_array_by_performing_queries; + +// #Medium #Array #Hash_Table #Sorting #Heap_Priority_Queue #Simulation +// #2024_04_16_Time_50_ms_(99.96%)_Space_77.2_MB_(15.35%) + +@SuppressWarnings({"java:S1871", "java:S6541"}) +public class Solution { + public long[] unmarkedSumArray(int[] nums, int[][] queries) { + int l = nums.length; + int[] orig = new int[l]; + for (int i = 0; i < l; i++) { + orig[i] = i; + } + int x = 1; + while (x < l) { + int[] temp = new int[l]; + int[] teor = new int[l]; + int y = 0; + while (y < l) { + int s1 = 0; + int s2 = 0; + while (s1 + s2 < 2 * x && y + s1 + s2 < l) { + if (s2 >= x || y + x + s2 >= l) { + temp[y + s1 + s2] = nums[y + s1]; + teor[y + s1 + s2] = orig[y + s1]; + s1++; + } else if (s1 >= x) { + temp[y + s1 + s2] = nums[y + x + s2]; + teor[y + s1 + s2] = orig[y + x + s2]; + s2++; + } else if (nums[y + s1] <= nums[y + x + s2]) { + temp[y + s1 + s2] = nums[y + s1]; + teor[y + s1 + s2] = orig[y + s1]; + s1++; + } else { + temp[y + s1 + s2] = nums[y + x + s2]; + teor[y + s1 + s2] = orig[y + x + s2]; + s2++; + } + } + y += 2 * x; + } + for (int i = 0; i < l; i++) { + nums[i] = temp[i]; + orig[i] = teor[i]; + } + x *= 2; + } + int[] change = new int[l]; + for (int i = 0; i < l; i++) { + change[orig[i]] = i; + } + boolean[] mark = new boolean[l]; + int m = queries.length; + int st = 0; + long sum = 0; + for (int num : nums) { + sum += num; + } + long[] out = new long[m]; + for (int i = 0; i < m; i++) { + int a = queries[i][0]; + if (!mark[change[a]]) { + mark[change[a]] = true; + sum -= nums[change[a]]; + } + int b = queries[i][1]; + int many = 0; + while (many < b) { + if (st == l) { + out[i] = sum; + break; + } + if (!mark[st]) { + mark[st] = true; + sum -= nums[st]; + many++; + } + st++; + } + out[i] = sum; + } + return out; + } +} diff --git a/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/readme.md b/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/readme.md new file mode 100644 index 000000000..839656b3b --- /dev/null +++ b/src/main/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/readme.md @@ -0,0 +1,47 @@ +3080\. Mark Elements on Array by Performing Queries + +Medium + +You are given a **0-indexed** array `nums` of size `n` consisting of positive integers. + +You are also given a 2D array `queries` of size `m` where queries[i] = [indexi, ki]. + +Initially all elements of the array are **unmarked**. + +You need to apply `m` queries on the array in order, where on the ith query you do the following: + +* Mark the element at index indexi if it is not already marked. +* Then mark ki unmarked elements in the array with the **smallest** values. If multiple such elements exist, mark the ones with the smallest indices. And if less than ki unmarked elements exist, then mark all of them. + +Return _an array answer of size_ `m` _where_ `answer[i]` _is the **sum** of unmarked elements in the array after the_ ith _query_. + +**Example 1:** + +**Input:** nums = [1,2,2,1,2,3,1], queries = [[1,2],[3,3],[4,2]] + +**Output:** [8,3,0] + +**Explanation:** + +We do the following queries on the array: + +* Mark the element at index `1`, and `2` of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [**1**,**2**,2,**1**,2,3,1]. The sum of unmarked elements is `2 + 2 + 3 + 1 = 8`. +* Mark the element at index `3`, since it is already marked we skip it. Then we mark `3` of the smallest unmarked elements with the smallest indices, the marked elements now are nums = [**1**,**2**,**2**,**1**,**2**,3,**1**]. The sum of unmarked elements is `3`. +* Mark the element at index `4`, since it is already marked we skip it. Then we mark `2` of the smallest unmarked elements with the smallest indices if they exist, the marked elements now are nums = [**1**,**2**,**2**,**1**,**2**,**3**,**1**]. The sum of unmarked elements is `0`. + +**Example 2:** + +**Input:** nums = [1,4,2,3], queries = [[0,1]] + +**Output:** [7] + +**Explanation:** We do one query which is mark the element at index `0` and mark the smallest element among unmarked elements. The marked elements will be nums = [**1**,4,**2**,3], and the sum of unmarked elements is `4 + 3 = 7`. + +**Constraints:** + +* `n == nums.length` +* `m == queries.length` +* 1 <= m <= n <= 105 +* 1 <= nums[i] <= 105 +* `queries[i].length == 2` +* 0 <= indexi, ki <= n - 1 \ No newline at end of file diff --git a/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/Solution.java b/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/Solution.java new file mode 100644 index 000000000..a63807510 --- /dev/null +++ b/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/Solution.java @@ -0,0 +1,49 @@ +package g3001_3100.s3081_replace_question_marks_in_string_to_minimize_its_value; + +// #Medium #String #Hash_Table #Sorting #Greedy #Heap_Priority_Queue #Counting +// #2024_04_16_Time_12_ms_(99.56%)_Space_45.4_MB_(97.69%) + +public class Solution { + public String minimizeStringValue(String s) { + int n = s.length(); + int time = 0; + int[] count = new int[26]; + int[] res = new int[26]; + char[] str = s.toCharArray(); + for (char c : str) { + if (c != '?') { + count[c - 'a']++; + } else { + time++; + } + } + int minTime = Integer.MAX_VALUE; + for (int i = 0; i < 26; i++) { + minTime = Math.min(minTime, count[i]); + } + while (time > 0) { + for (int j = 0; j < 26; j++) { + if (count[j] == minTime) { + res[j]++; + count[j]++; + time--; + } + if (time == 0) { + break; + } + } + minTime++; + } + int start = 0; + for (int i = 0; i < n; i++) { + if (str[i] == '?') { + while (res[start] == 0) { + start++; + } + str[i] = (char) ('a' + start); + res[start]--; + } + } + return new String(str); + } +} diff --git a/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/readme.md b/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/readme.md new file mode 100644 index 000000000..1bf54f2a4 --- /dev/null +++ b/src/main/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/readme.md @@ -0,0 +1,53 @@ +3081\. Replace Question Marks in String to Minimize Its Value + +Medium + +You are given a string `s`. `s[i]` is either a lowercase English letter or `'?'`. + +For a string `t` having length `m` containing **only** lowercase English letters, we define the function `cost(i)` for an index `i` as the number of characters **equal** to `t[i]` that appeared before it, i.e. in the range `[0, i - 1]`. + +The **value** of `t` is the **sum** of `cost(i)` for all indices `i`. + +For example, for the string `t = "aab"`: + +* `cost(0) = 0` +* `cost(1) = 1` +* `cost(2) = 0` +* Hence, the value of `"aab"` is `0 + 1 + 0 = 1`. + +Your task is to **replace all** occurrences of `'?'` in `s` with any lowercase English letter so that the **value** of `s` is **minimized**. + +Return _a string denoting the modified string with replaced occurrences of_ `'?'`_. If there are multiple strings resulting in the **minimum value**, return the lexicographically smallest one._ + +**Example 1:** + +**Input:** s = "???" + +**Output:** "abc" + +**Explanation:** In this example, we can replace the occurrences of `'?'` to make `s` equal to `"abc"`. + +For `"abc"`, `cost(0) = 0`, `cost(1) = 0`, and `cost(2) = 0`. + +The value of `"abc"` is `0`. + +Some other modifications of `s` that have a value of `0` are `"cba"`, `"abz"`, and, `"hey"`. + +Among all of them, we choose the lexicographically smallest. + +**Example 2:** + +**Input:** s = "a?a?" + +**Output:** "abac" + +**Explanation:** In this example, the occurrences of `'?'` can be replaced to make `s` equal to `"abac"`. + +For `"abac"`, `cost(0) = 0`, `cost(1) = 0`, `cost(2) = 1`, and `cost(3) = 0`. + +The value of `"abac"` is `1`. + +**Constraints:** + +* 1 <= s.length <= 105 +* `s[i]` is either a lowercase English letter or `'?'`. \ No newline at end of file diff --git a/src/test/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/SolutionTest.java b/src/test/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/SolutionTest.java new file mode 100644 index 000000000..9692fa746 --- /dev/null +++ b/src/test/java/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/SolutionTest.java @@ -0,0 +1,22 @@ +package g3001_3100.s3076_shortest_uncommon_substring_in_an_array; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void shortestSubstrings() { + assertThat( + new Solution().shortestSubstrings(new String[] {"cab", "ad", "bad", "c"}), + equalTo(new String[] {"ab", "", "ba", ""})); + } + + @Test + void shortestSubstrings2() { + assertThat( + new Solution().shortestSubstrings(new String[] {"abc", "bcd", "abcd"}), + equalTo(new String[] {"", "", "abcd"})); + } +} diff --git a/src/test/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/SolutionTest.java b/src/test/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/SolutionTest.java new file mode 100644 index 000000000..bbe969221 --- /dev/null +++ b/src/test/java/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays/SolutionTest.java @@ -0,0 +1,23 @@ +package g3001_3100.s3077_maximum_strength_of_k_disjoint_subarrays; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void maximumStrength() { + assertThat(new Solution().maximumStrength(new int[] {1, 2, 3, -1, 2}, 3), equalTo(22L)); + } + + @Test + void maximumStrength2() { + assertThat(new Solution().maximumStrength(new int[] {12, -2, -2, -2, -2}, 5), equalTo(64L)); + } + + @Test + void maximumStrength3() { + assertThat(new Solution().maximumStrength(new int[] {-1, -2, -3}, 1), equalTo(-1L)); + } +} diff --git a/src/test/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/SolutionTest.java b/src/test/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/SolutionTest.java new file mode 100644 index 000000000..99b85e99c --- /dev/null +++ b/src/test/java/g3001_3100/s3079_find_the_sum_of_encrypted_integers/SolutionTest.java @@ -0,0 +1,18 @@ +package g3001_3100.s3079_find_the_sum_of_encrypted_integers; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void sumOfEncryptedInt() { + assertThat(new Solution().sumOfEncryptedInt(new int[] {1, 2, 3}), equalTo(6)); + } + + @Test + void sumOfEncryptedInt2() { + assertThat(new Solution().sumOfEncryptedInt(new int[] {10, 21, 31}), equalTo(66)); + } +} diff --git a/src/test/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/SolutionTest.java b/src/test/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/SolutionTest.java new file mode 100644 index 000000000..9b8cc29d7 --- /dev/null +++ b/src/test/java/g3001_3100/s3080_mark_elements_on_array_by_performing_queries/SolutionTest.java @@ -0,0 +1,28 @@ +package g3001_3100.s3080_mark_elements_on_array_by_performing_queries; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import com_github_leetcode.CommonUtils; +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void unmarkedSumArray() { + assertThat( + new Solution() + .unmarkedSumArray( + new int[] {1, 2, 2, 1, 2, 3, 1}, + CommonUtils + .convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray( + "[1,2],[3,3],[4,2]")), + equalTo(new long[] {8, 3, 0})); + } + + @Test + void unmarkedSumArray2() { + assertThat( + new Solution().unmarkedSumArray(new int[] {1, 4, 2, 3}, new int[][] {{0, 1}}), + equalTo(new long[] {7})); + } +} diff --git a/src/test/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/SolutionTest.java b/src/test/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/SolutionTest.java new file mode 100644 index 000000000..5177bf6fa --- /dev/null +++ b/src/test/java/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value/SolutionTest.java @@ -0,0 +1,18 @@ +package g3001_3100.s3081_replace_question_marks_in_string_to_minimize_its_value; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minimizeStringValue() { + assertThat(new Solution().minimizeStringValue("???"), equalTo("abc")); + } + + @Test + void minimizeStringValue2() { + assertThat(new Solution().minimizeStringValue("a?a?"), equalTo("abac")); + } +}