Non-Adjacent Combinations of Two Words
Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order.
Input
The input will be a single line containing a sentence.
Output
For example, if the given sentence is "python is a programming language", the possible unique combination of two are (a, is), (a, language), (a, programming), (a, python), (is, language), (is, programming), (is, python), (language, programming), (language, python), (programming, python).
a python
is language
is programming
language python
programming python
Sample Input 1
raju always plays cricket
Sample Output 1
always cricket
cricket raju
plays raju
Sample Input 2
python is a programming language
Sample Output 2
a language
a python
is language
is programming
language python
programming python
Sample Input 3
to be or not to be
Sample Output 3
be be
be not
or to
to to
Comments
Leave a comment