Google Interview Question
Java DevelopersCountry: United States
push all edges into a map - the key represent both items, as a pair.
now iterate over map & for each element, search the reverse in the same map.
if its found, we have the reverse.
overall runtime is linear time bcz map is O(1) per operation.
scan is on map so it naturally eliminates duplicates from input - bcz these are eliminated when we push them to the map (unique key)
Please, clarify the question.
- denis.zayats February 21, 2018Because, if we talk about Adjacency matrix for undirected graph - it's is a symmetric matrix, so, the answer will be always True.