Simple solution with sets
just use two set for reference named as valid and invalid. \n\n\nclass Solution {\n    public int numMatchingSubseq(String s, String[] words) {\n        int cou
just use two set for reference named as valid and invalid. \n\n```\nclass Solution {\n    public int numMatchingSubseq(String s, String[] words) {\n        int count = 0;\n        Set<String> valid = new HashSet<>();\n        Set<String> invalid = new HashSet<>();\n        for(String word: words){\n            if(isSubSequence(s, word, valid, invalid))\n                count++;\n        }\n        return count;\n    }\n    \n    public boolean isSubSequence(String s, String word, Set<String> valid, Set<String> invalid){\n        if(valid.contains(word))\n            return true;\n        else if(invalid.contains(word))\n            return false;\n        \n        int sPtr = 0;\n        int wPtr = 0;\n        while(sPtr < s.length() && wPtr < word.length()){\n            if(s.charAt(sPtr) == word.charAt(wPtr)){\n                wPtr++;\n            }\n            if(wPtr == word.length()){\n                valid.add(word);\n                return true;\n            }\n            sPtr++;\n        }\n        invalid.add(word);\n        return false;\n    }\n}\n```
['Two Pointers', 'Dynamic Programming', 'Ordered Set']