27. Largest Color Value In A Directed Graph | Code
Hard

Problem Statement

Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.

Examples

1Example 1
Input:
{ "colors": "abaca", "edges": [ [ 0, 1 ], [ 0, 2 ], [ 2, 3 ], [ 3, 4 ] ] }
Output:
3
2Example 2
Input:
{ "colors": "a", "edges": [ [ 0, 0 ] ] }
Output:
-1
3Example 3
Input:
{ "colors": "hhqhuq", "edges": [ [ 0, 1 ], [ 0, 2 ], [ 2, 3 ], [ 3, 4 ], [ 3, 5 ], [ 5, 1 ] ] }
Output:
3
Loading...

Sign in to Run Code and Submit