-
Notifications
You must be signed in to change notification settings - Fork 0
/
MissingAlphabet.java
44 lines (38 loc) · 1.53 KB
/
MissingAlphabet.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.smlnskgmail.jaman.codewarsjava.kyu6;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
// https://www.codewars.com/kata/5ad1e412cc2be1dbfb000016
public class MissingAlphabet {
private final String input;
public MissingAlphabet(String input) {
this.input = input;
}
public String solution() {
List<String> parsedInput = Arrays
.stream(input.split(""))
.collect(Collectors.toList());
List<String> alphabet = Arrays
.stream("ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""))
.collect(Collectors.toList());
List<String> usedLetters = new ArrayList<>();
return input.chars().mapToObj(value -> {
char character = (char) value;
String letter = String.valueOf(character);
StringBuilder resultForSymbol = new StringBuilder(letter);
if (!usedLetters.contains(letter)) {
int positionInAlphabet = value - 96;
while (positionInAlphabet < 26) {
String letterInAlphabet = alphabet.get(positionInAlphabet);
if (!parsedInput.contains(letterInAlphabet.toLowerCase())) {
resultForSymbol.append(letterInAlphabet);
}
positionInAlphabet++;
}
usedLetters.add(letter);
}
return resultForSymbol.toString();
}).collect(Collectors.joining(""));
}
}