Practice Largest Color Value in a Directed Graph
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Largest Color Value in a Directed Graph
Problem Statement
There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1. You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0-indexed). You are also given a 2D array edges where edges[j] = [aj, bj] indicates that there is a directed edge from node aj to node bj. A valid path in the graph is a sequence of nodes x1 -> x2 -> x3 -> ... -> xk such that there is a directed edge from xi to xi+1 for every 1 <= i < k. The color value of the path is the number of nodes that are colored the most frequently occurring color along that path. Return the largest color value of any valid path in the given graph, or -1 if the graph contains a cycle.
Source: Largest Color Value in a Directed Graph on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]
3
# Example 2
colors = "a", edges = [[0,0]]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Largest Color Value in a Directed Graph.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.