{"id":"24e4f93c-2d00-4798-b23e-d595440ca9d0","name":"Stream Of Characters","description":"Implement the StreamChecker class as follows:\r\n\r\n1. StreamChecker(words): Constructor, init the data structure with the given words.\r\n2. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. Words will only consist of lowercase English letters.\r\n2. Queries will only consist of lowercase English letters","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nclass StreamChecker {\n\n StreamChecker(vector<string>& words) {\n\n }\n\n bool query(char letter) {\n\n }\n};\n\n\n\nint main() {\n int n;\n cin >> n;\n\n vector<string> words(n);\n\n for (int i = 0; i < n; ++i)\n cin >> words[i];\n\n StreamChecker* obj = new StreamChecker(words);\n cin >> n;\n for (int i = 0; i < n; i++) {\n char ch;\n cin >> ch;\n if (obj->query(ch)) {\n cout << \"true\" << endl;\n }\n else {\n cout << \"false\" << endl;\n }\n }\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static class StreamChecker {\r\n public StreamChecker(String[] words) {\r\n\r\n }\r\n\r\n public boolean query(char letter) {\r\n\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n\r\n String[]words = new String[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n words[i] = read.readLine();\r\n }\r\n\r\n StreamChecker obj = new StreamChecker(words);\r\n\r\n n = Integer.parseInt(read.readLine());\r\n for (int i = 0; i < n; i++) {\r\n System.out.println(obj.query(read.readLine().charAt(0)));\r\n }\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\ncd\r\nf\r\nkl\r\n12\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\n","sampleOutput":"false\r\nfalse\r\nfalse\r\ntrue\r\nfalse\r\ntrue\r\nfalse\r\nfalse\r\nfalse\r\nfalse\r\nfalse\r\ntrue\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"c64ab4d6-ad12-4df7-830e-42b6cceafb8d","name":"Stream Of Characters MCQ","slug":"stream-of-characters-mcq","type":0},{"id":"2051476e-0834-4ac7-9fcb-f2a4a48fe2d5","name":"Stream Of Characters","slug":"stream-of-characters","type":1}],"next":null,"prev":null}}

Stream Of Characters

Implement the StreamChecker class as follows: 1. StreamChecker(words): Constructor, init the data structure with the given words. 2. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.

{"id":"24e4f93c-2d00-4798-b23e-d595440ca9d0","name":"Stream Of Characters","description":"Implement the StreamChecker class as follows:\r\n\r\n1. StreamChecker(words): Constructor, init the data structure with the given words.\r\n2. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1. Words will only consist of lowercase English letters.\r\n2. Queries will only consist of lowercase English letters","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\n\nusing namespace std;\n\nclass StreamChecker {\n\n StreamChecker(vector<string>& words) {\n\n }\n\n bool query(char letter) {\n\n }\n};\n\n\n\nint main() {\n int n;\n cin >> n;\n\n vector<string> words(n);\n\n for (int i = 0; i < n; ++i)\n cin >> words[i];\n\n StreamChecker* obj = new StreamChecker(words);\n cin >> n;\n for (int i = 0; i < n; i++) {\n char ch;\n cin >> ch;\n if (obj->query(ch)) {\n cout << \"true\" << endl;\n }\n else {\n cout << \"false\" << endl;\n }\n }\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static class StreamChecker {\r\n public StreamChecker(String[] words) {\r\n\r\n }\r\n\r\n public boolean query(char letter) {\r\n\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader read = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(read.readLine());\r\n\r\n String[]words = new String[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n words[i] = read.readLine();\r\n }\r\n\r\n StreamChecker obj = new StreamChecker(words);\r\n\r\n n = Integer.parseInt(read.readLine());\r\n for (int i = 0; i < n; i++) {\r\n System.out.println(obj.query(read.readLine().charAt(0)));\r\n }\r\n }\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\ncd\r\nf\r\nkl\r\n12\r\na\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\nl\r\n","sampleOutput":"false\r\nfalse\r\nfalse\r\ntrue\r\nfalse\r\ntrue\r\nfalse\r\nfalse\r\nfalse\r\nfalse\r\nfalse\r\ntrue\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"4b4725b5-4896-4b68-aae2-03ea1e2ecbb2","name":"Trie For Intermediate","slug":"trie-for-intermediate-9996","type":0},{"id":"c64ab4d6-ad12-4df7-830e-42b6cceafb8d","name":"Stream Of Characters MCQ","slug":"stream-of-characters-mcq","type":0},{"id":"2051476e-0834-4ac7-9fcb-f2a4a48fe2d5","name":"Stream Of Characters","slug":"stream-of-characters","type":1}],"next":null,"prev":null}}
plane

Editor


Loading...

Stream Of Characters

medium

Implement the StreamChecker class as follows: 1. StreamChecker(words): Constructor, init the data structure with the given words. 2. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.

Constraints

1. Words will only consist of lowercase English letters. 2. Queries will only consist of lowercase English letters

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

3 cd f kl 12 a b c d e f g h i j k l

Sample Output

false false false true false true false false false false false true

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode