-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGemstones.java
More file actions
39 lines (28 loc) · 776 Bytes
/
Gemstones.java
File metadata and controls
39 lines (28 loc) · 776 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
29
30
31
32
33
34
35
36
37
38
39
//https://www.hackerrank.com/challenges/gem-stones?h_r=next-challenge&h_v=zen
import java.util.*;
public class Gemstones
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int numTestCases = s.nextInt();
HashSet<Character> baseSet = new HashSet<Character>();
HashSet<Character> currSet = new HashSet<Character>();
for (char c = 'a'; c <= 'z'; c++)
{
baseSet.add(c);
}
while (numTestCases > 0)
{
currSet.clear();
char[] currentRockElements = s.next().toCharArray();
for (int i = 0; i < currentRockElements.length; i++)
{
currSet.add(currentRockElements[i]);
}
baseSet.retainAll(currSet);
--numTestCases;
}
System.out.println(baseSet.size());
}
}