-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboardRow.java
More file actions
66 lines (57 loc) · 1.58 KB
/
KeyboardRow.java
File metadata and controls
66 lines (57 loc) · 1.58 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package HashTable;
import java.util.*;
/**
* Author - archit.s
* Date - 21/08/18
* Time - 12:10 PM
*/
public class KeyboardRow {
public String[] findWords(String[] words) {
Map<Character, Integer> map = new HashMap<>();
map.put('Q', 1);
map.put('W', 1);
map.put('E', 1);
map.put('R', 1);
map.put('T', 1);
map.put('Y', 1);
map.put('U', 1);
map.put('I', 1);
map.put('O', 1);
map.put('P', 1);
map.put('A', 2);
map.put('S', 2);
map.put('D', 2);
map.put('F', 2);
map.put('G', 2);
map.put('H', 2);
map.put('J', 2);
map.put('K', 2);
map.put('L', 2);
map.put('Z', 3);
map.put('X', 3);
map.put('C', 3);
map.put('V', 3);
map.put('B', 3);
map.put('N', 3);
map.put('M', 3);
List<String> l = new LinkedList<>();
for(int i=0; i<words.length; i++){
int value = map.get(Character.toUpperCase(words[i].charAt(0)));
int flag = 1;
for(int j=1; j<words[i].length(); j++){
if(map.get(Character.toUpperCase(words[i].charAt(j))) != value){
flag = 0;
break;
}
}
if(flag == 1){
l.add(words[i]);
}
}
return l.toArray(new String[0]);
}
public static void main(String[] args) {
String[] input = new String[]{"ALASKA"};
System.out.println(Arrays.toString(new KeyboardRow().findWords(input)));
}
}