#K53642. Remove Duplicate Words
Remove Duplicate Words
Remove Duplicate Words
Nina loves string manipulation and is working on an interesting problem. Given a sentence, remove all duplicate words while preserving the order of their first appearance. A word is defined as a sequence of non-space characters. The output must maintain the order in which each unique word first appears.
Input: A single line containing a sentence that may include alphabets, digits, and special characters.
Output: A single line containing the unique words from the input sentence.
Mathematically, if the input sentence is split into words \(w_1, w_2, \dots, w_n\), then the output is the sequence of words \(w_{i_1}, w_{i_2}, \dots, w_{i_k}\) where each word appears for the first time.
inputFormat
The input consists of a single line containing a sentence. The sentence may include alphabets, numbers, and special characters. Words are separated by whitespace.
outputFormat
The output is a single line containing the unique words from the input sentence, preserving the order of their first occurrence, separated by a space.
## sampleI love to code and I love to learn
I love to code and learn