Home › Interview Questions › Given a list of words, return a list of booleans i…

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.

🟢 Easy Coding Fresher level
1Times asked
Aug 2026Last seen
Aug 2026First seen

šŸ’” 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