Hackerrank Sparse Arrays Solution in Java
String[] stringArr = new String[n];

        for (int i = 0; i &lt; n; i++){
                stringArr[i] = scan.next();              
            }



Why use an array?  Consider 

        Map&lt;String, Integer&gt; inputCounts = new HashMap&lt;&gt;(n);

        for (int i = 0; i &lt; n; i++) {
            String input = scan.next();

            Integer count = inputCounts.get(input);
            if (count == null) {
                count = 0;
            }

            count++;
            inputCounts.put(input, count);
        }


Now you know the count for each input string.  So 


                String stringQue = scan.next();

                int occNum = 0;
                for (int j = 0; j &lt; n; j++){
                    if (stringQue.equals(stringArr[j])) occNum++;
                }
             System.out.println(occNum);



could become just 

                String query = scan.next();

                Integer count = inputCounts.get(query);
                if (count == null) {
                    count = 0;
                }                          

                System.out.println(count);


If the overhead of the hash accesses is less than the overhead of the for loop, this might be faster.  

A HashMap converts the string key into a location in the Map.  This is more expensive than a numeric array selection but is probably similar to the cost of the equals method.  

I think that we can safely say that accessing the HashMap is going to be faster than iterating over every member of the array unless the array is tiny.  The larger question is if the cost of building the HashMap is going to be greater than the savings in processing the queries.  For a large number of strings and a small number of queries, the cost of building the HashMap can outweigh the savings in processing the queries.  That's trivially true if there are zero queries.  And may still be true for one query.  There is some point where it stops being true.  You'd have to benchmark to be sure.  

I prefer names like query and count to stringQue and occNum.