Skip to content

Commit ab3e764

Browse files
* docs: kata description * feat: kata/sum-of-minimums --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent cc599fc commit ab3e764

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@
529529
- [Sum of array singles](sum-of-array-singles "59f11118a5e129e591000134")
530530
- [Sum of Cubes](sum-of-cubes "59a8570b570190d313000037")
531531
- [Sum of differences between products and LCMs](sum-of-differences-between-products-and-lcms "56e56756404bb1c950000992")
532+
- [Sum of Minimums!](sum-of-minimums "5d5ee4c35162d9001af7d699")
532533
- [Sum of numbers from 0 to N](sum-of-numbers-from-0-to-n "56e9e4f516bcaa8d4f001763")
533534
- [Sum of Odd Cubed Numbers](sum-of-odd-cubed-numbers "580dda86c40fa6c45f00028a")
534535
- [Sum of odd numbers](sum-of-odd-numbers "55fd2d567d94ac3bc9000064")

kata/7-kyu/sum-of-minimums/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [Sum of Minimums!](https://www.codewars.com/kata/sum-of-minimums "https://www.codewars.com/kata/5d5ee4c35162d9001af7d699")
2+
3+
Given a 2D (nested) list (array, vector, …) of size `m * n`, your task is to find the sum of the minimum values in each row.
4+
5+
For Example:
6+
7+
```
8+
[ [ 1, 2, 3, 4, 5 ] # minimum value of row is 1
9+
, [ 5, 6, 7, 8, 9 ] # minimum value of row is 5
10+
, [ 20, 21, 34, 56, 100 ] # minimum value of row is 20
11+
]
12+
```
13+
14+
So the function should return `26` because the sum of the minimums is `1 + 5 + 20 = 26`.
15+
16+
Note: You will always be given a non-empty list containing positive values.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import static java.util.Arrays.stream;
2+
3+
interface Kata {
4+
static int sumOfMinimums(int[][] arr) {
5+
return stream(arr).mapToInt(row -> stream(row).min().orElse(0)).sum();
6+
}
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
import static org.junit.jupiter.params.provider.Arguments.arguments;
3+
4+
import java.util.stream.Stream;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.jupiter.params.provider.MethodSource;
8+
9+
class SumOfMinimumsTest {
10+
private static Stream<Arguments> testData() {
11+
return Stream.of(
12+
arguments(new int[][]{{7, 9, 8, 6, 2}, {6, 3, 5, 4, 3}, {5, 8, 7, 4, 5}}, 9),
13+
arguments(new int[][]{{11, 12, 14, 54}, {67, 89, 90, 56}, {7, 9, 4, 3}, {9, 8, 6, 7}}, 76));
14+
}
15+
16+
@ParameterizedTest
17+
@MethodSource("testData")
18+
void sample(int[][] arr, int expected) {
19+
assertEquals(expected, Kata.sumOfMinimums(arr));
20+
}
21+
}

0 commit comments

Comments
 (0)