using lower_bound binary search and hashmap
\n    class Solution {\n    public int numMatchingSubseq(String s, String[] words) {\n        Map> m=new HashMap<>();\n        for(int i=0;i<s.length();i++){\n 
\n    class Solution {\n    public int numMatchingSubseq(String s, String[] words) {\n        Map<Character,List<Integer>> m=new HashMap<>();\n        for(int i=0;i<s.length();i++){\n            if(!m.containsKey(s.charAt(i))){\n                m.put(s.charAt(i),new ArrayList<>());\n            }\n            m.get(s.charAt(i)).add(i);\n        }\n      \n         int c=0;\n        for(String x:words){\n           int i=0;int prev=-1;\n            for(;i<x.length();i++){\n                if(m.containsKey(x.charAt(i))){\n                    List<Integer> l1=m.get(x.charAt(i));\n          \n                    if(prev==-1){\n                        prev=l1.get(0);\n                    }\n                    else{\n                        int lb=lower_bound(l1,prev+1);\n                  //      System.out.print(lb+" ");\n                        if(lb==-1)break;\n                        prev=l1.get(lb);\n                    }\n                }\n                else{\n                    break;\n                }\n            }\n            \n            if(i==x.length())c++;\n        }\n        return c;\n    }\n    //finding lower_bound\n    public int lower_bound(List<Integer> l1,int k){\n        int ans=-1;\n        int l=0;\n        int h=l1.size()-1;\n        while(l<=h){\n            int mid=(l+h)/2;\n            if(l1.get(mid)>=k){\n                ans=mid;\n                h=mid-1;\n            }\n            else{\n                l=mid+1;\n            }\n        }\n        return ans;\n    }\n}
['Binary Tree']