Most Frequent Label Along Any Path in a Content Pipeline DAG
Last updated: November 29, 2026
Quick Overview
A content processing pipeline is a directed graph of n stages, and each stage has a single lowercase letter label. The value of a path is the count of its most frequent label. Return the largest value over all paths, or -1 if the graph contains a cycle.
Meta
November 29, 20260
0
0 solved
A content processing pipeline is a directed graph of n stages, and each stage has a single lowercase letter label. The value of a path is the count of its most frequent label. Return the largest value over all paths, or -1 if the graph contains a cycle.
A hard Meta onsite question that disguises a DP on a DAG inside an ML pipeline story, such as stages tagged by model family in an integrity classification flow. The interviewer checks that you avoid enumerating paths, keep a 26-wide DP per node, propagate in topological order, and detect cycles in the same pass.
What the Interviewer Expects
- Reject path enumeration as exponential
- Define dp[v][c] as the max count of label c on a path ending at v
- Propagate dp along edges in Kahn order
- Add the node's own label when it is popped
- Detect cycles by the processed count
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the path itself, not just the value?
- What if labels come from an alphabet of size one million?
- How would you answer the question for paths of length at most L?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
labels, a string of lengthn(label of nodeiislabels[i]), andedges[u, v]. - Output: the maximum, over all directed paths, of the highest single-letter count on that path; `-1...
High-Level Design
Paths can be exponential in number, but the value only needs per-label maxima. Define:
= the largest number of nodes labeled c on any path ending at v.
When v is processed, its inco...