You are given a list of historical sentences sentences and an integer array times, where sentences[i] is a previously typed sentence and times[i] is the number of times it has been typed. Implement the AutocompleteSystem class:
AutocompleteSystem(String[] sentences, int[] times) initializes the system with the given sentences and their corresponding frequencies.List<String> input(char c) is called whenever the user types a character c:c is not the character '#', append c to the current input prefix and return the top 3 historical sentences that have the current prefix. The returned sentences should be sorted by:c is the character '#', the current input prefix is considered a completed sentence. Add it to the historical records (or increment its frequency if it already exists), reset the current prefix to empty, and return an empty list.You should design the system to efficiently support up to 5000 calls to input.
Constraints:
n == sentences.length == times.length1 <= n <= 1001 <= sentences[i].length <= 1001 <= times[i] <= 50c is a lowercase letter, a space ' ', or '#'.input will not exceed 200.Return the list of top 3 matching sentences for each call to input (except when c == '#', in which case return an empty list).
Need help or want more practice?