Given a list of words, return a list of booleans indicating whether each word has been seen before. Use a HashSet for O(1) lookups.
š” Model Answer
To solve this problem efficiently, iterate through the input list once while maintaining a HashSet of words that have already been seen. For each word, check if it exists in the set. If it does, append True to the result list (indicating the word has appeared before); otherwise, append False and add the word to the set. This approach ensures each lookup and insertion is O(1) on average, giving an overall time complexity of O(n) and space complexity of O(n) for the set and result list. The algorithm is straightforward, making it suitable for beginners and demonstrates the practical use of hash-based collections for duplicate detection.
This answer was generated by AI for study purposes. Use it as a starting point ā personalize it with your own experience.
š¤ Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI ā Starts at ā¹500