Quick Overview

This question evaluates skills in efficient membership testing for large datasets, memory-time trade-offs in data structures, and string handling concerns such as case sensitivity and Unicode normalization.

Check strings against dictionary efficiently

Company: Reevo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

Given a large dictionary of unique words and a list of query strings, return for each query whether it exists in the dictionary. The dictionary may contain up to 1,000,000 words and the query list up to 100,000 strings. Optimize for many queries and minimal memory overhead. Describe your chosen data structure(s), expected time and space complexity, and how you would handle case sensitivity, Unicode normalization, and duplicate queries.

Quick Answer: This question evaluates skills in efficient membership testing for large datasets, memory-time trade-offs in data structures, and string handling concerns such as case sensitivity and Unicode normalization.

Given a large dictionary of unique words and a list of query strings, return for each query (in order) whether it exists in the dictionary. Implement `solution(dictionary, queries)` that returns a list of booleans where the i-th element is `true` if `queries[i]` is present in `dictionary`, and `false` otherwise. The dictionary may contain up to 1,000,000 words and the query list up to 100,000 strings, so optimize for many lookups: build a hash set from the dictionary once (O(N)) and answer each query in expected O(1). Comparison is exact and case-sensitive ('Cat' and 'cat' are distinct). Example: dictionary = ["apple", "banana", "cherry"] queries = ["apple", "grape", "cherry"] returns [true, false, true]

Constraints

  • 0 <= len(dictionary) <= 1,000,000
  • All words in dictionary are unique
  • 0 <= len(queries) <= 100,000
  • Comparison is exact and case-sensitive
  • Strings consist of printable characters

Examples

Input: (['apple', 'banana', 'cherry'], ['apple', 'grape', 'cherry'])

Expected Output: [True, False, True]

Explanation: 'apple' and 'cherry' are in the dictionary; 'grape' is not.

Input: ([], ['apple'])

Expected Output: [False]

Explanation: Empty dictionary: no query can match.

Hints

  1. Build a hash set from the dictionary once so each membership check is expected O(1) instead of scanning the whole list per query.
  2. Process queries in order and append the boolean result for each — duplicate queries simply produce repeated results.
  3. Be explicit about case sensitivity: by default exact comparison means 'Cat' != 'cat'. If you needed case-insensitive matching you would normalize (e.g. casefold) both the dictionary and the queries before inserting/looking up.

Loading coding console...