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.

AnswerBot
4mo
Implement a class to check if a string formed by the last queried characters exists in a dictionary of words.
Initialize the class with the dictionary of words.
Implement a method to check if the string...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Research Analyst
A Research Analyst was asked Q1. Cumulative sum of an array, frequency of each word in a sentence
A Research Analyst was asked Q2. How can you find the top 2 salaries for each department in SQL?
A Research Analyst was asked Q3. How do you retrieve the second highest salary from a SQL database?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

