Skip to content

Commit 42ea198

Browse files
authoredMar 1, 2024
Added tasks 3026-3030
1 parent bdf1d4f commit 42ea198

File tree

15 files changed

+553
-0
lines changed

15 files changed

+553
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package g3001_3100.s3026_maximum_good_subarray_sum;
2+
3+
// #Medium #Array #Hash_Table #Prefix_Sum #2024_03_01_Time_62_ms_(93.52%)_Space_56.2_MB_(95.77%)
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
public class Solution {
9+
private static final int NO_GOOD_SUBARRAYS = 0;
10+
11+
public long maximumSubarraySum(int[] input, int targetDifference) {
12+
Map<Integer, Long> valueToMinPrefixSum = new HashMap<>();
13+
long prefixSum = 0;
14+
long maxSubarraySum = Long.MIN_VALUE;
15+
for (int value : input) {
16+
if (valueToMinPrefixSum.containsKey(value + targetDifference)) {
17+
maxSubarraySum =
18+
Math.max(
19+
maxSubarraySum,
20+
prefixSum
21+
+ value
22+
- valueToMinPrefixSum.get(value + targetDifference));
23+
}
24+
if (valueToMinPrefixSum.containsKey(value - targetDifference)) {
25+
maxSubarraySum =
26+
Math.max(
27+
maxSubarraySum,
28+
prefixSum
29+
+ value
30+
- valueToMinPrefixSum.get(value - targetDifference));
31+
}
32+
if (!valueToMinPrefixSum.containsKey(value)
33+
|| valueToMinPrefixSum.get(value) > prefixSum) {
34+
valueToMinPrefixSum.put(value, prefixSum);
35+
}
36+
prefixSum += value;
37+
}
38+
return maxSubarraySum != Long.MIN_VALUE ? maxSubarraySum : NO_GOOD_SUBARRAYS;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
3026\. Maximum Good Subarray Sum
2+
3+
Medium
4+
5+
You are given an array `nums` of length `n` and a **positive** integer `k`.
6+
7+
A subarray of `nums` is called **good** if the **absolute difference** between its first and last element is **exactly** `k`, in other words, the subarray `nums[i..j]` is good if `|nums[i] - nums[j]| == k`.
8+
9+
Return _the **maximum** sum of a **good** subarray of_ `nums`. _If there are no good subarrays__, return_ `0`.
10+
11+
**Example 1:**
12+
13+
**Input:** nums = [1,2,3,4,5,6], k = 1
14+
15+
**Output:** 11
16+
17+
**Explanation:** The absolute difference between the first and last element must be 1 for a good subarray. All the good subarrays are: [1,2], [2,3], [3,4], [4,5], and [5,6]. The maximum subarray sum is 11 for the subarray [5,6].
18+
19+
**Example 2:**
20+
21+
**Input:** nums = [-1,3,2,4,5], k = 3
22+
23+
**Output:** 11
24+
25+
**Explanation:** The absolute difference between the first and last element must be 3 for a good subarray. All the good subarrays are: [-1,3,2], and [2,4,5]. The maximum subarray sum is 11 for the subarray [2,4,5].
26+
27+
**Example 3:**
28+
29+
**Input:** nums = [-1,-2,-3,-4], k = 2
30+
31+
**Output:** -6
32+
33+
**Explanation:** The absolute difference between the first and last element must be 2 for a good subarray. All the good subarrays are: [-1,-2,-3], and [-2,-3,-4]. The maximum subarray sum is -6 for the subarray [-1,-2,-3].
34+
35+
**Constraints:**
36+
37+
* <code>2 <= nums.length <= 10<sup>5</sup></code>
38+
* <code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code>
39+
* <code>1 <= k <= 10<sup>9</sup></code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package g3001_3100.s3027_find_the_number_of_ways_to_place_people_ii;
2+
3+
// #Hard #Array #Math #Sorting #Enumeration #Geometry
4+
// #2024_03_01_Time_59_ms_(69.95%)_Space_45.3_MB_(20.75%)
5+
6+
import java.util.Arrays;
7+
8+
public class Solution {
9+
private int customCompare(int[] p1, int[] p2) {
10+
if (p1[0] != p2[0]) {
11+
return Integer.signum(p1[0] - p2[0]);
12+
}
13+
return Integer.signum(p2[1] - p1[1]);
14+
}
15+
16+
public int numberOfPairs(int[][] points) {
17+
Arrays.sort(points, this::customCompare);
18+
int count = 0;
19+
for (int i = 0; i < points.length; ++i) {
20+
int m = Integer.MIN_VALUE;
21+
for (int j = i + 1; j < points.length; ++j) {
22+
if ((points[i][1] >= points[j][1]) && (points[j][1] > m)) {
23+
m = points[j][1];
24+
count++;
25+
}
26+
}
27+
}
28+
return count;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
3027\. Find the Number of Ways to Place People II
2+
3+
Hard
4+
5+
You are given a 2D array `points` of size `n x 2` representing integer coordinates of some points on a 2D-plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.
6+
7+
We define the **right** direction as positive x-axis (**increasing x-coordinate**) and the **left** direction as negative x-axis (**decreasing x-coordinate**). Similarly, we define the **up** direction as positive y-axis (**increasing y-coordinate**) and the **down** direction as negative y-axis (**decreasing y-coordinate**)
8+
9+
You have to place `n` people, including Alice and Bob, at these points such that there is **exactly one** person at every point. Alice wants to be alone with Bob, so Alice will build a rectangular fence with Alice's position as the **upper left corner** and Bob's position as the **lower right corner** of the fence (**Note** that the fence **might not** enclose any area, i.e. it can be a line). If any person other than Alice and Bob is either **inside** the fence or **on** the fence, Alice will be sad.
10+
11+
Return _the number of **pairs of points** where you can place Alice and Bob, such that Alice **does not** become sad on building the fence_.
12+
13+
**Note** that Alice can only build a fence with Alice's position as the upper left corner, and Bob's position as the lower right corner. For example, Alice cannot build either of the fences in the picture below with four corners `(1, 1)`, `(1, 3)`, `(3, 1)`, and `(3, 3)`, because:
14+
15+
* With Alice at `(3, 3)` and Bob at `(1, 1)`, Alice's position is not the upper left corner and Bob's position is not the lower right corner of the fence.
16+
* With Alice at `(1, 3)` and Bob at `(1, 1)`, Bob's position is not the lower right corner of the fence.
17+
18+
![](https://assets.leetcode.com/uploads/2024/01/04/example0alicebob-1.png)
19+
20+
**Example 1:**
21+
22+
![](https://assets.leetcode.com/uploads/2024/01/04/example1alicebob.png)
23+
24+
**Input:** points = [[1,1],[2,2],[3,3]]
25+
26+
**Output:** 0
27+
28+
**Explanation:** There is no way to place Alice and Bob such that Alice can build a fence with Alice's position as the upper left corner and Bob's position as the lower right corner. Hence we return 0.
29+
30+
**Example 2:**
31+
32+
![](https://assets.leetcode.com/uploads/2024/02/04/example2alicebob.png)
33+
34+
**Input:** points = [[6,2],[4,4],[2,6]]
35+
36+
**Output:** 2
37+
38+
**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
39+
- Place Alice at (4, 4) and Bob at (6, 2).
40+
- Place Alice at (2, 6) and Bob at (4, 4). You cannot place Alice at (2, 6) and Bob at (6, 2) because the person at (4, 4) will be inside the fence.
41+
42+
**Example 3:**
43+
44+
![](https://assets.leetcode.com/uploads/2024/02/04/example4alicebob.png)
45+
46+
**Input:** points = [[3,1],[1,3],[1,1]]
47+
48+
**Output:** 2
49+
50+
**Explanation:** There are two ways to place Alice and Bob such that Alice will not be sad:
51+
- Place Alice at (1, 1) and Bob at (3, 1).
52+
- Place Alice at (1, 3) and Bob at (1, 1).
53+
54+
You cannot place Alice at (1, 3) and Bob at (3, 1) because the person at (1, 1) will be on the fence.
55+
56+
Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
57+
58+
**Constraints:**
59+
60+
* `2 <= n <= 1000`
61+
* `points[i].length == 2`
62+
* <code>-10<sup>9</sup> <= points[i][0], points[i][1] <= 10<sup>9</sup></code>
63+
* All `points[i]` are distinct.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package g3001_3100.s3028_ant_on_the_boundary;
2+
3+
// #Easy #Array #Simulation #Prefix_Sum #2024_03_01_Time_0_ms_(100.00%)_Space_42.1_MB_(53.10%)
4+
5+
public class Solution {
6+
public int returnToBoundaryCount(int[] nums) {
7+
int ans = 0;
8+
int num = 0;
9+
for (int n : nums) {
10+
num += n;
11+
if (num == 0) {
12+
ans++;
13+
}
14+
}
15+
return ans;
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
3028\. Ant on the Boundary
2+
3+
Easy
4+
5+
An ant is on a boundary. It sometimes goes **left** and sometimes **right**.
6+
7+
You are given an array of **non-zero** integers `nums`. The ant starts reading `nums` from the first element of it to its end. At each step, it moves according to the value of the current element:
8+
9+
* If `nums[i] < 0`, it moves **left** by `-nums[i]` units.
10+
* If `nums[i] > 0`, it moves **right** by `nums[i]` units.
11+
12+
Return _the number of times the ant **returns** to the boundary._
13+
14+
**Notes:**
15+
16+
* There is an infinite space on both sides of the boundary.
17+
* We check whether the ant is on the boundary only after it has moved `|nums[i]|` units. In other words, if the ant crosses the boundary during its movement, it does not count.
18+
19+
**Example 1:**
20+
21+
**Input:** nums = [2,3,-5]
22+
23+
**Output:** 1
24+
25+
**Explanation:** After the first step, the ant is 2 steps to the right of the boundary.
26+
27+
After the second step, the ant is 5 steps to the right of the boundary.
28+
29+
After the third step, the ant is on the boundary. So the answer is 1.
30+
31+
**Example 2:**
32+
33+
**Input:** nums = [3,2,-3,-4]
34+
35+
**Output:** 0
36+
37+
**Explanation:** After the first step, the ant is 3 steps to the right of the boundary.
38+
39+
After the second step, the ant is 5 steps to the right of the boundary.
40+
41+
After the third step, the ant is 2 steps to the right of the boundary.
42+
43+
After the fourth step, the ant is 2 steps to the left of the boundary.
44+
45+
The ant never returned to the boundary, so the answer is 0.
46+
47+
**Constraints:**
48+
49+
* `1 <= nums.length <= 100`
50+
* `-10 <= nums[i] <= 10`
51+
* `nums[i] != 0`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package g3001_3100.s3029_minimum_time_to_revert_word_to_initial_state_i;
2+
3+
// #Medium #String #Hash_Function #String_Matching #Rolling_Hash
4+
// #2024_03_01_Time_1_ms_(99.70%)_Space_42.7_MB_(8.42%)
5+
6+
public class Solution {
7+
public int minimumTimeToInitialState(String word, int k) {
8+
int n = word.length();
9+
for (int i = k; i < n; i += k) {
10+
if (word.substring(i, n).equals(word.substring(0, n - i))) {
11+
return i / k;
12+
}
13+
}
14+
return (n + k - 1) / k;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
3029\. Minimum Time to Revert Word to Initial State I
2+
3+
Medium
4+
5+
You are given a **0-indexed** string `word` and an integer `k`.
6+
7+
At every second, you must perform the following operations:
8+
9+
* Remove the first `k` characters of `word`.
10+
* Add any `k` characters to the end of `word`.
11+
12+
**Note** that you do not necessarily need to add the same characters that you removed. However, you must perform **both** operations at every second.
13+
14+
Return _the **minimum** time greater than zero required for_ `word` _to revert to its **initial** state_.
15+
16+
**Example 1:**
17+
18+
**Input:** word = "abacaba", k = 3
19+
20+
**Output:** 2
21+
22+
**Explanation:** At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac". At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state. It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.
23+
24+
**Example 2:**
25+
26+
**Input:** word = "abacaba", k = 4
27+
28+
**Output:** 1
29+
30+
**Explanation:** At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state. It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.
31+
32+
**Example 3:**
33+
34+
**Input:** word = "abcbabcd", k = 2
35+
36+
**Output:** 4
37+
38+
**Explanation:** At every second, we will remove the first 2 characters of word, and add the same characters to the end of word. After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state. It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.
39+
40+
**Constraints:**
41+
42+
* `1 <= word.length <= 50`
43+
* `1 <= k <= word.length`
44+
* `word` consists only of lowercase English letters.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package g3001_3100.s3030_find_the_grid_of_region_average;
2+
3+
// #Medium #Array #Matrix #2024_03_01_Time_53_ms_(98.79%)_Space_88.4_MB_(35.20%)
4+
5+
public class Solution {
6+
public int[][] resultGrid(int[][] image, int threshold) {
7+
int n = image.length;
8+
int m = image[0].length;
9+
int[][] intensity = new int[n][m];
10+
int[][] count = new int[n][m];
11+
for (int i = 1; i < n - 1; i++) {
12+
for (int j = 1; j < m - 1; j++) {
13+
boolean regionPossible = true;
14+
int regionSum = 0;
15+
int r0c0 = image[i - 1][j - 1];
16+
int r0c1 = image[i - 1][j];
17+
int r0c2 = image[i - 1][j + 1];
18+
int r1c0 = image[i][j - 1];
19+
int r1c1 = image[i][j];
20+
int r1c2 = image[i][j + 1];
21+
int r2c0 = image[i + 1][j - 1];
22+
int r2c1 = image[i + 1][j];
23+
int r2c2 = image[i + 1][j + 1];
24+
regionSum += (r0c0 + r0c1 + r0c2 + r1c0 + r1c1 + r1c2 + r2c0 + r2c1 + r2c2);
25+
if (Math.abs(r0c0 - r0c1) > threshold
26+
|| Math.abs(r0c0 - r1c0) > threshold
27+
|| Math.abs(r0c1 - r0c0) > threshold
28+
|| Math.abs(r0c1 - r1c1) > threshold
29+
|| Math.abs(r0c1 - r0c2) > threshold
30+
|| Math.abs(r0c2 - r0c1) > threshold
31+
|| Math.abs(r0c2 - r1c2) > threshold
32+
|| Math.abs(r1c0 - r1c1) > threshold
33+
|| Math.abs(r1c2 - r1c1) > threshold
34+
|| Math.abs(r2c0 - r2c1) > threshold
35+
|| Math.abs(r2c0 - r1c0) > threshold
36+
|| Math.abs(r2c1 - r2c0) > threshold
37+
|| Math.abs(r2c1 - r1c1) > threshold
38+
|| Math.abs(r2c1 - r2c2) > threshold
39+
|| Math.abs(r2c2 - r2c1) > threshold
40+
|| Math.abs(r2c2 - r1c2) > threshold) {
41+
regionPossible = false;
42+
}
43+
if (regionPossible) {
44+
regionSum /= 9;
45+
for (int k = -1; k <= 1; k++) {
46+
for (int l = -1; l <= 1; l++) {
47+
intensity[i + k][j + l] += regionSum;
48+
count[i + k][j + l]++;
49+
}
50+
}
51+
}
52+
}
53+
}
54+
for (int i = 0; i < n; i++) {
55+
for (int j = 0; j < m; j++) {
56+
if (count[i][j] == 0) {
57+
intensity[i][j] = image[i][j];
58+
} else {
59+
intensity[i][j] = intensity[i][j] / count[i][j];
60+
}
61+
}
62+
}
63+
return intensity;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
3030\. Find the Grid of Region Average
2+
3+
Medium
4+
5+
You are given a **0-indexed** `m x n` grid `image` which represents a grayscale image, where `image[i][j]` represents a pixel with intensity in the range`[0..255]`. You are also given a **non-negative** integer `threshold`.
6+
7+
Two pixels `image[a][b]` and `image[c][d]` are said to be **adjacent** if `|a - c| + |b - d| == 1`.
8+
9+
A **region** is a `3 x 3` subgrid where the **absolute difference** in intensity between any two **adjacent** pixels is **less than or equal to** `threshold`.
10+
11+
All pixels in a **region** belong to that region, note that a pixel **can** belong to **multiple** regions.
12+
13+
You need to calculate a **0-indexed** `m x n` grid `result`, where `result[i][j]` is the **average** intensity of the region to which `image[i][j]` belongs, **rounded down** to the nearest integer. If `image[i][j]` belongs to multiple regions, `result[i][j]` is the **average** of the **rounded down average** intensities of these regions, **rounded down** to the nearest integer. If `image[i][j]` does **not** belong to any region, `result[i][j]` is **equal to** `image[i][j]`.
14+
15+
Return _the grid_ `result`.
16+
17+
**Example 1:**
18+
19+
![](https://assets.leetcode.com/uploads/2023/12/21/example0corrected.png)
20+
21+
**Input:** image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3
22+
23+
**Output:** [[9,9,9,9],[9,9,9,9],[9,9,9,9]]
24+
25+
**Explanation:** There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 9, while the average intensity of the second region is 9.67 which is rounded down to 9. The average intensity of both of the regions is (9 + 9) / 2 = 9. As all the pixels belong to either region 1, region 2, or both of them, the intensity of every pixel in the result is 9. Please note that the rounded-down values are used when calculating the average of multiple regions, hence the calculation is done using 9 as the average intensity of region 2, not 9.67.
26+
27+
**Example 2:**
28+
29+
![](https://assets.leetcode.com/uploads/2023/12/21/example1corrected.png)
30+
31+
**Input:** image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12
32+
33+
**Output:** [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]
34+
35+
**Explanation:** There exist two regions in the image, which are shown as the shaded areas in the picture. The average intensity of the first region is 25, while the average intensity of the second region is 30. The average intensity of both of the regions is (25 + 30) / 2 = 27.5 which is rounded down to 27. All the pixels in row 0 of the image belong to region 1, hence all the pixels in row 0 in the result are 25. Similarly, all the pixels in row 3 in the result are 30. The pixels in rows 1 and 2 of the image belong to region 1 and region 2, hence their assigned value is 27 in the result.
36+
37+
**Example 3:**
38+
39+
**Input:** image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1
40+
41+
**Output:** [[5,6,7],[8,9,10],[11,12,13]]
42+
43+
**Explanation:** There does not exist any region in image, hence result[i][j] == image[i][j] for all the pixels.
44+
45+
**Constraints:**
46+
47+
* `3 <= n, m <= 500`
48+
* `0 <= image[i][j] <= 255`
49+
* `0 <= threshold <= 255`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package g3001_3100.s3026_maximum_good_subarray_sum;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class SolutionTest {
9+
@Test
10+
void maximumSubarraySum() {
11+
assertThat(
12+
new Solution().maximumSubarraySum(new int[] {1, 2, 3, 4, 5, 6}, 1), equalTo(11L));
13+
}
14+
15+
@Test
16+
void maximumSubarraySum2() {
17+
assertThat(new Solution().maximumSubarraySum(new int[] {-1, 3, 2, 4, 5}, 3), equalTo(11L));
18+
}
19+
20+
@Test
21+
void maximumSubarraySum3() {
22+
assertThat(new Solution().maximumSubarraySum(new int[] {-1, -2, -3, -4}, 2), equalTo(-6L));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package g3001_3100.s3027_find_the_number_of_ways_to_place_people_ii;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class SolutionTest {
9+
@Test
10+
void numberOfPairs() {
11+
assertThat(new Solution().numberOfPairs(new int[][] {{1, 1}, {2, 2}, {3, 3}}), equalTo(0));
12+
}
13+
14+
@Test
15+
void numberOfPairs2() {
16+
assertThat(new Solution().numberOfPairs(new int[][] {{6, 2}, {4, 4}, {2, 6}}), equalTo(2));
17+
}
18+
19+
@Test
20+
void numberOfPairs3() {
21+
assertThat(new Solution().numberOfPairs(new int[][] {{3, 1}, {1, 3}, {1, 1}}), equalTo(2));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package g3001_3100.s3028_ant_on_the_boundary;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class SolutionTest {
9+
@Test
10+
void returnToBoundaryCount() {
11+
assertThat(new Solution().returnToBoundaryCount(new int[] {2, 3, -5}), equalTo(1));
12+
}
13+
14+
@Test
15+
void returnToBoundaryCount2() {
16+
assertThat(new Solution().returnToBoundaryCount(new int[] {3, 2, -3, -4}), equalTo(0));
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package g3001_3100.s3029_minimum_time_to_revert_word_to_initial_state_i;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class SolutionTest {
9+
@Test
10+
void minimumTimeToInitialState() {
11+
assertThat(new Solution().minimumTimeToInitialState("abacaba", 3), equalTo(2));
12+
}
13+
14+
@Test
15+
void minimumTimeToInitialState2() {
16+
assertThat(new Solution().minimumTimeToInitialState("abacaba", 4), equalTo(1));
17+
}
18+
19+
@Test
20+
void minimumTimeToInitialState3() {
21+
assertThat(new Solution().minimumTimeToInitialState("abcbabcd", 2), equalTo(4));
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package g3001_3100.s3030_find_the_grid_of_region_average;
2+
3+
import static org.hamcrest.CoreMatchers.equalTo;
4+
import static org.hamcrest.MatcherAssert.assertThat;
5+
6+
import com_github_leetcode.CommonUtils;
7+
import org.junit.jupiter.api.Test;
8+
9+
class SolutionTest {
10+
@Test
11+
void resultGrid() {
12+
assertThat(
13+
new Solution()
14+
.resultGrid(
15+
CommonUtils
16+
.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
17+
"[5,6,7,10],[8,9,10,10],[11,12,13,10]"),
18+
3),
19+
equalTo(
20+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
21+
"[9,9,9,9],[9,9,9,9],[9,9,9,9]")));
22+
}
23+
24+
@Test
25+
void resultGrid2() {
26+
assertThat(
27+
new Solution()
28+
.resultGrid(
29+
CommonUtils
30+
.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
31+
"[10,20,30],[15,25,35],[20,30,40],[25,35,45]"),
32+
12),
33+
equalTo(
34+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
35+
"[25,25,25],[27,27,27],[27,27,27],[30,30,30]")));
36+
}
37+
38+
@Test
39+
void resultGrid3() {
40+
assertThat(
41+
new Solution()
42+
.resultGrid(
43+
CommonUtils
44+
.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
45+
"[5,6,7],[8,9,10],[11,12,13]"),
46+
1),
47+
equalTo(
48+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
49+
"[5,6,7],[8,9,10],[11,12,13]")));
50+
}
51+
}

0 commit comments

Comments
 (0)
Please sign in to comment.