We're given two strings that act as search queries. We need to determine if they're the same. For example:
Query 1: stock price rate
Query 2: share cost rate
We're also given a list containing where each entry has two words that are synonyms. the words could be repeated meaning a transitive relation exists. Something like this:
[
[cost,price]
[rate,price]
[share,equity]
]
Goal is determine whether the queries mean the same thing.
I've proposed a solution where i group similar meaning words into lists and doing an exhaustive search until we find the word from query1 and then searching it's group for word from query 2. But the interviewer wanted a more efficient approach which i couldn't figure out. Is there a more efficient way to solve this issue?