Shortest Substring hackerrank
import java.io.*; import java.lang.*; import java.util.*; class sm{ static int smallestSubstring(String a) { // Stores all occurrences ArrayList a1 = new ArrayList<>(); // Generate all the substrings for(int i = 0; i < a.length(); i++) { for(int j = i + 1; j <= a.length(); j++) { // Avoid multiple occurences if (i != j) // Append all substrings a1.add(a.substring(i, j)); } } // Take into account // all the substrings TreeMap a2 = new TreeMap<>(); for(String s : a1) a2.put(s, a2.getOrDefault(s, 0) + 1); ArrayList freshlist = new ArrayList<>(); // Iterate over all // unique substrings for(String s : a2.keySet()) { // If frequency is 1 if (a2.get(s) == 1) // Append into fresh list freshlist.add(s); } // Initia