Stream of Characters Problem Statement
You are provided with a list, DICTIONARY[]
, which contains a collection of words, along with a stream of characters (queries). The task is to implement a class CharacterStreamChecker using an appropriate data structure. This class needs to be designed with the following functionality:
Explanation:
- CharacterStreamChecker(dictionary): A constructor to initialize the data structure with the words provided in
DICTIONARY[]
. - solveQuery(character): A method to determine whether the string formed by the last
C
queried characters (whereC >= 1
), ordered from oldest to newest and including the most recently queried character, exists in theDICTIONARY[]
. Returntrue
if the string exists, otherwise returnfalse
.
Input:
The input follows this format:
The first line consists of an integer 'T', denoting the number of test cases.
The first line of each test case consists of an integer ‘N’, indicating the number of words in ‘DICTIONARY[]’.
The second line includes ‘N’ space-separated strings representing the words in ‘DICTIONARY[]’.
The third line contains an integer ‘Q’, representing the number of character queries.
The last line contains ‘Q’ space-separated characters.
Output:
For each query in the test cases, output true
if the string formed by the last ‘C’ characters (C >= 1) is found in DICTIONARY[]
.
Otherwise, output false
.
Print each test case's result on a separate line.
Example:
Example:
Input:
DICTIONARY[] = ['app', 'apple', 'banana']
Query Stream: ['a', 'p', 'p', 'l', 'e']
Output:
false
false
true
false
true
Constraints:
- 1 <= T <= 5
- 1 <= N <= 200
- 1 <= |DICTIONARY[i]| <= 200
- 1 <= Q <= 400
- Each word and query consists of lowercase English letters only.
- Time limit per test case: 1 second.
Note:
The dictionary contains only unique strings. You do not need to print anything; just implement the provided function to achieve the desired functionality.
Be the first one to answer
Add answer anonymously...
Top Amazon Research Analyst interview questions & answers
Popular interview questions of Research Analyst
Top HR questions asked in Amazon Research Analyst
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app