import java.util.*; public class NumberOfMatchingSubseqs { private boolean isSubseq(String w, String S) { if(w.length() == 0) return true; int i = 0, j = 0; for(; i subseq = new HashSet<> (); Set notSubseq = new HashSet<> (); for(String w: words) { if(subseq.contains(w)) results += 1; else if(notSubseq.contains(w)) continue; else { if(isSubseq(w, S)) { results += 1; subseq.add(w); } else { notSubseq.add(w); } } } return results; } }