Find Common Ancestors in a Directed Graph

Given a directed acyclic graph (DAG), each edge u v means that node u is a direct parent of node v. Given two nodes a and b, return all of their common ancestors.

A node x is an ances...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: