Given a list of synonyms and queries as inputs:
Synonyms
[
["abc", "def", "ghi"],
["pq", "rs", "uv"],
["abc", "uv"],
["jk", "rs"],
["wrg", "yu", "io"]
]Queries:
[
["abc", "pq"],
["jk", "abc"],
["abc", "uv"],
["zy", "xxx"],
["zy", "xxx"]
]Implement count distinct queries function:
function countDistinctQueries(synonyms, queries) {}Explanation
["abc", "pq"] // distinct
["jk", "abc"] // distinct
["abc", "uv"] // duplicate, since ["abc", "pq"] is already a query
["zy", "xxx"] // does not exist in synonym dictionary, hence distinct
["zy", "xxx"] // does not exist in synonym dictionary but already seen argument, hence duplicate
Output - 3Comments (3)


