As reported: LinkedIn SDE 2 screening round 1, Mar 2025: Kth Largest Element in an Array, then Largest Color Value in a Directed Graph.
A directed graph has n nodes, 0..n−1. colors[i] is the lowercase letter coloring node i, and edges[j] = [a, b] is a directed edge a → b. The color value of a path is the number of nodes on it with the most frequent color. Return the largest color value of any valid path, or −1 if the graph contains a cycle.
This is LeetCode 1857 — Largest Color Value in a Directed Graph.
Example 1
colors = "abaca", edges = [[0,1],[0,2],[2,3],[3,4]]
Output: 3 (path 0 → 2 → 3 → 4 has three "a")
Example 2
colors = "a", edges = [[0,0]]
Output: -1 (a cycle)
Constraints: 1 ≤ n ≤ 10^5; 0 ≤ edges.length ≤ 10^5; colors has lowercase letters only.
Code runner format: LeetCode's test-case format, one JSON value per line (one line per argument). Implement largestPathValue(colors, edges); the harness prints the result.