Files

33 lines
966 B
Java
Raw Permalink Normal View History

2017-04-09 19:12:53 -05:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-04-09 19:12:53 -05:00
import java.util.Scanner;
import java.util.BitSet;
public class Solution {
private static final int NUM_ELEMENTS = 26;
2017-09-11 09:32:17 -07:00
public static void main(String[] args) {
2017-04-09 19:12:53 -05:00
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
/* Initialize BitSet */
BitSet bitset = new BitSet(NUM_ELEMENTS);
bitset.set(0, NUM_ELEMENTS);
/* Create a BitSet for each rock. "AND" it with our original BitSet */
for (int r = 0; r < N; r++) {
String rock = scan.next();
BitSet currBitSet = new BitSet(NUM_ELEMENTS);
for (int i = 0; i < rock.length(); i++) {
currBitSet.set(rock.charAt(i) - 'a');
}
bitset.and(currBitSet);
}
scan.close();
System.out.println(bitset.cardinality());
}
}