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
Coding & Algorithms
Machine Learning Engineer
Meta
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

0

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
DP on DAG
topological order
cycle detection
path counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: labels, a string of length n (label of node i is labels[i]), and edges [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:

dp[v][c]dp[v][c] = the largest number of nodes labeled c on any path ending at v.

When v is processed, its inco...


Submit Your Answer
Markdown supported