Implement Prefix Search and Node Removal
Problem Description
This interview consists of two distinct coding tasks:
Task 1: Prefix Search Data Structure
Implement a data structure that supports efficient prefix-based string operations. It must provide the following functionalities:
insert(word): Adds a givenwordto the data structure.count_with_prefix(prefix): Returns the total number of words currently stored in the data structure that begin with the specifiedprefix.
Follow-up Questions:
- Case-Insensitive Matching: How would you modify your implementation to make
count_with_prefixcase-insensitive? - Input Normalization: Before storing or querying, how would you normalize input strings by removing any trailing digits using a regular expression?
Task 2: Linked List Node Removal
Given the head of a singly linked list and a target value x, remove all nodes from the list whose value is equal to x. The function should return the head of the modified linked list.
AI interview prep
Core dilemma
Balancing the efficiency of string prefix search (especially with large datasets) against the complexities introduced by case-insensitivity and dynamic input normalization, while ensuring correctness and optimal resource usage for both tasks.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Prefix Search and Node Removal
Problem Description
This interview consists of two distinct coding tasks:
Task 1: Prefix Search Data Structure
Implement a data structure that supports efficient prefix-based string operations. It must provide the following functionalities:
insert(word): Adds a givenwordto the data structure.count_with_prefix(prefix): Returns the total number of words currently stored in the data structure that begin with the specifiedprefix.
Follow-up Questions:
- Case-Insensitive Matching: How would you modify your implementation to make
count_with_prefixcase-insensitive? - Input Normalization: Before storing or querying, how would you normalize input strings by removing any trailing digits using a regular expression?
Task 2: Linked List Node Removal
Given the head of a singly linked list and a target value x, remove all nodes from the list whose value is equal to x. The function should return the head of the modified linked list.