JAVA | Java Parallel Streams | NOT FOR KIDS!
This approach uses advanced concept of parrallel streams in java.\n Although this might be a non-optimal approach for solving this problem but it demonstrates a
* This approach uses advanced concept of parrallel streams in java.\n* Although this might be a non-optimal approach for solving this problem but it demonstrates a different paradigm of processing tasks which are independent to each other.\n* Processing for each word can be done independently here, that is why we can run them parallelly.\n```\nclass Solution {\n\tpublic int numMatchingSubseq(String s, String[] words) {\n\t\tAtomicInteger x = new AtomicInteger();\n\t\tMap<String, Integer> mp = new HashMap<>();\n\t\tArrays.stream(words).forEach(word ->{\n\t\t\tmp.put(word, mp.getOrDefault(word, 0) + 1);\n\t\t});\n\t\tint n = s.length();\n\t\tmp.keySet().stream().parallel().forEach(word ->{\n\t\t\tint m = word.length(), j = 0;\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tif(j == m){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(s.charAt(i) == word.charAt(j)){\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(j == m){\n\t\t\t\tx.addAndGet(mp.get(word));\n\t\t\t}\n\t\t});\n\n\t\treturn x.intValue();\n\t}\n}\n```
['Java']