Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Synonymous Sentences
MEDIUM
20 mins
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Synonymous Sentences

Contributed by
Vishal Modani
Medium
yellow-spark
0/80
Avg time to solve 20 mins
Success Rate 80 %
Share
0 upvotes

Problem Statement

You are given a sentence consisting of several space-separated words and a list of pairs of synonyms. Your task is to find out all possible sentences that can be formed by replacing any word in the sentence with any of its synonyms.

Note :

1. A word may or may not have synonyms.
2. There can be multiple synonyms for a single word.
3. All words only contain lowercase English letters.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
1
2 5
bright pleasant happy bright
today is a pleasant day
Sample Output 1 :
today is a bright day
today is a happy day
today is a pleasant day
Explanation For Sample Input 1 :
In the first test case, we can see that “bright” is a synonym of “pleasant”. We can also see that “happy” is also a synonym of “bright”. This means that “bright”, “pleasant” and “happy” are all synonyms. Hence we can form three different sentences using these words one by one. 
Reset Code
Full screen
Auto
copy-code
Console