Uber | SDE2 Frontend | DSA Round
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-10-16Added By Anonymous
Source: Link
Company: Uber
Role: SDE2 Frontend
Interview Stage: Phone Screen
Original Post Content:
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 - 3