-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompleteArray.txt
More file actions
28 lines (19 loc) · 906 Bytes
/
completeArray.txt
File metadata and controls
28 lines (19 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Challenge:
Looks like some hoodlum plumber and his brother has been running around and damaging your stages again.
The pipes connecting your level's stages together need to be fixed before you receive any more complaints.
The pipes are correct when each pipe after the first is 1 more than the previous one.
Task
Given a list of unique numbers sorted in ascending order, return a new list so that the values increment by 1 for each index from the minimum value up to the maximum value (both included).
Example
Input: 1,3,5,6,7,8 Output: 1,2,3,4,5,6,7,8
-----------------
Solution:
import java.util.Arrays;
import java.util.stream.IntStream;
public class Kata {
public static int[] pipeFix(int[] numbers) {
int lowerNum = Arrays.stream(numbers).min().orElse(0);
int higherNum = Arrays.stream(numbers).max().orElse(0);
return IntStream.rangeClosed(lowerNum,higherNum).toArray();
}
}