Largest Color Value in a Directed Graph
A hard-tier problem at 58% community acceptance, tagged with Hash Table, Dynamic Programming, Graph. Reported in interviews at Juspay and 1 others.
Largest Color Value in a Directed Graph is a hard problem that LinkedIn and Juspay have actually asked. It combines graph traversal with color counting in a way that trips up candidates who don't see the topological sort angle. The 57.6% acceptance rate tells you it's not a random slog, there's a clean pattern here, but you have to find it. If this one comes up during your live OA and you freeze on the approach, StealthCoder surfaces the solution in seconds while the proctor sees nothing.
Companies that ask "Largest Color Value in a Directed Graph"
Largest Color Value in a Directed Graph is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe trap is trying to count colors naively while traversing the graph. Most candidates start with DFS and get stuck on cycle detection or redundant recalculation. The real trick is topological sort plus memoization. You need to process nodes in dependency order so that when you visit a node, all its predecessors are already done. Once you sort topologically, dynamic programming handles the color counting, each node tracks the maximum count of each color along all paths that reach it. Hash tables store the color counts per node. Without the topo sort framework, you recompute the same paths over and over. StealthCoder is your safety net if the cycle-handling and DP state design go sideways during the assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Largest Color Value in a Directed Graph recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Largest Color Value in a Directed Graph interview FAQ
Why doesn't plain DFS work here?+
DFS alone can't guarantee you've seen all incoming edges before processing a node. You'll recompute color counts multiple times and struggle with cycle detection. Topological sort enforces the order so DP logic is sound. It's the prerequisite, not optional.
Is this still asked at LinkedIn and other big companies?+
Yes. LinkedIn and Juspay have both asked it, and the 57.6% pass rate means it's recent enough to stay in rotation. It's hard enough to separate solid engineers from mediocre ones, but fair if you know the pattern.
What's the real trick to the color counting part?+
Use a hash table at each node to track the maximum count of each color seen on any path leading to it. When you visit a node in topo order, merge the color counts from all predecessors, increment the node's own color, and store the result. This avoids recomputation.
How do Hash Table and Dynamic Programming relate in this problem?+
Hash tables store the DP state (color counts per node). Instead of a fixed 2D array, you use a dictionary for each node to track variable colors. This keeps memory bounded and lets you look up and update counts in constant time.
How important is cycle detection here?+
Critical. The problem assumes a directed acyclic graph for topo sort to work. You must detect cycles upfront, usually with DFS and a visited/recursion stack. If you skip it, your topo sort is garbage and DP fails silently.
Want the actual problem statement? View "Largest Color Value in a Directed Graph" on LeetCode →