Counting the gems among the rocks John has discovered various rocks. Each rock is composed of various
  elements, and each element is represented by a lowercase Latin letter
  from 'a' to 'z'. An element can be present multiple times in a rock.
  An element is called a 'gem-element' if it occurs at least once in
  each of the rocks.
  
  Given the list of rocks with their compositions, you have to print how
  many different kinds of gems-elements he has.
  
  Input Format
  
  The first line consists of N, the number of rocks. Each of the next N
  lines contain rocks’ composition. Each composition consists of small
  alphabets of English language.
  
  Output Format
  
  Print the number of different kinds of gem-elements he has.
  
  Constraints
  
  \$1 ≤ N ≤ 100\$
  
  Each composition consists of only small Latin letters ('a'-'z'). 1 ≤ Length of each composition ≤ 100
  
  Sample Input

3
abcdde
baccd
eeabg 

  
  Sample Output

2 

  
  Explanation
  
  Only "a", "b" are the two kind of gem-elements, since
  these characters occur in each of the rocks’ composition.




I tried to solve this HackerRank problem in Java. Do you see any areas for improvement?

public int getGems(List&lt;String&gt; list) {

    if (list != null &amp;&amp; !(list.size() &gt; 0)) {
        throw new IllegalArgumentException("Invalid Input");
    }

    int gemsCount = 0;
    int s = list.size();
    int cnt = 1;

    // assume list(0) will always have gems
    String str = list.get(0);
    char[] ch = str.toCharArray();
    for (char c : ch) {
        for (int i = 1; i &lt; s; i++) {
            String st = list.get(i);
            if (st.indexOf(c) &gt; -1) {
                cnt++;
                continue;
            } else {
                cnt = 1;
                break;
            }
        }
        if (cnt == s) {
            gemsCount++;
            cnt = 1;
        }
    }
    return gemsCount;
}
I find your variable naming maddening. For example, list is just about the least informative name possible for a list, and str and st are just about the least informative names possible for strings.

The input validation is a bit awkwardly expressed.  Also, if list is null, then it will still crash with a NullPointerException.

The comment is a bit misleading.

The many places where you reset cnt make your code hard to follow.  Without changing your general strategy too much, here's how you could write it better:

public int getGems(List&lt;String&gt; rocks) {
    if (rocks == null || rocks.isEmpty()) {
        throw new IllegalArgumentException("No Input");
    }

    int gemsCount = 0;
    int n = rocks.size();

    // Use list(0) as a source of candidate gems
    char[] candidateGems = rocks.get(0).toCharArray();
    for (char c : candidateGems) {
        int appearances = 0;
        for (String rock : rocks) {
            if (rock.indexOf(c) &gt;= 0) {
                appearances++;
            } else {
                break;
            }
        }
        if (appearances == n) {
            gemsCount++;
        }
    }
    return gemsCount;
}