Solve three DSA problems: trie, window, intervals
Autocomplete Service
Design and implement an autocomplete service. Support insert(word) to add a word and suggest(prefix) to return up to five existing words that start with the given prefix. If fewer than five words exist, return all of them. The suggestions should be ordered lexicographically. Specify the time and space complexities of your solution.
Maximum Score from Decrypted Subarray
You are given an array value of integers and a boolean array decrypted of the same length, where decrypted[i] = 1 if the element at index i is already decrypted, and 0 otherwise. You are also given an integer k. You can perform at most one operation: choose a contiguous subarray of length at most k and treat all elements within that subarray as decrypted. The score is the sum of value[i] for all indices i that are decrypted after the operation. Compute the maximum achievable score using an O(n) algorithm.
Merge Overlapping Intervals
Given a list of closed integer ranges [li, ri], merge any ranges that overlap or touch. Two ranges [l1, r1] and [l2, r2] overlap or touch if r1 >= l2 - 1 (assuming l1 <= l2). Return the merged list of ranges, sorted by their start points. Implement the function and analyze its time and space complexity.
AI interview prep
Core dilemma
Balancing efficient data structure design for prefix matching and range operations with algorithmic optimization for scoring and merging.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve three DSA problems: trie, window, intervals
Autocomplete Service
Design and implement an autocomplete service. Support insert(word) to add a word and suggest(prefix) to return up to five existing words that start with the given prefix. If fewer than five words exist, return all of them. The suggestions should be ordered lexicographically. Specify the time and space complexities of your solution.
Maximum Score from Decrypted Subarray
You are given an array value of integers and a boolean array decrypted of the same length, where decrypted[i] = 1 if the element at index i is already decrypted, and 0 otherwise. You are also given an integer k. You can perform at most one operation: choose a contiguous subarray of length at most k and treat all elements within that subarray as decrypted. The score is the sum of value[i] for all indices i that are decrypted after the operation. Compute the maximum achievable score using an O(n) algorithm.
Merge Overlapping Intervals
Given a list of closed integer ranges [li, ri], merge any ranges that overlap or touch. Two ranges [l1, r1] and [l2, r2] overlap or touch if r1 >= l2 - 1 (assuming l1 <= l2). Return the merged list of ranges, sorted by their start points. Implement the function and analyze its time and space complexity.