Goldman Sachs Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
let's have a graph, where one vertex corresponds to one rectangle. Let's draw an edge from vertex A to B iff corresponding rectangle to B is inside rectangle corresponding to A. After this procedure we end up having DAG (directed acyclic graph). Run dfs(X) on it, to find number of vertexes in subtree rooted at X.
Completexity - O(n + m)
Memory - O(n + m)
where, n and m - number of vertices and edges in graph correspondingly
Seems like.. this problem can be achieved through Composite Design Pattern
- prad121 August 08, 2015