Challenge: Find a Mother Vertex in a Directed Graph

Try to solve the Find a Mother Vertex in a Directed Graph problem.

We'll cover the following

Statement

Given a directed graph as input, determine a mother vertex within it. A mother vertex in a graph G=(V,E)G = (V, E), is vertex VV such that all other vertices in GG can be reached by a path from VV. Although a graph might feature multiple mother vertices, your goal is to identify at least one.

Constraints:

  • 00 \leq graph.length 104\leq 10^4

  • 0V,E1030 \leq V, E \leq 10^3

  • VEV \neq E

  • There are no repeated edges.

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.