We create an empty hash table. Then split given string around spaces. For every word, we first check if it is in hash table or not. If not found in hash table, we print it and store in the hash table.
Input: str = “Geeks for Geeks A Computer Science portal for Geeks”
Output: Geeks for A Computer Science portal
Explanation: here ‘Geeks’ and ‘for’ are duplicate so these words are removed from the string
Input: “Publish your own articles on GeeksforGeeks and share your knowledge with the world”
Output: Publish your own articles on GeeksforGeeks and share knowledge with the world
Explanation: here ‘your’ is the duplicate word so that word is removed from string
Remove DuplicateRepeated words from String : https://www.geeksforgeeks.org/remove-duplicaterepeated-words-string/