Bird
Raised Fist0

Which node corresponds to the longest path ending with length 3?

hard🔄 Reverse Engineer Q9 of Q15
Topological Sort - Longest Path With Different Adjacent Characters
Given a DAG with 4 nodes and edges [[0,1],[1,2],[0,3]], and node characters s="abac", the dp array after processing topological order is [1,2,3,2]. Which node corresponds to the longest path ending with length 3?
ANode 2
BNode 0
CNode 3
DNode 1
Step-by-Step Solution
Solution:
  1. Step 1: Analyze dp array

    dp[2] = 3 indicates longest path ends at node 2 with length 3.
  2. Step 2: Confirm path validity

    Path 0(a) -> 1(b) -> 2(a) has length 3 with different adjacent characters.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Longest path length 3 ends at node 2 [OK]
Quick Trick: dp[i] stores longest path length ending at node i [OK]
Common Mistakes:
MISTAKES
  • Confusing node indices with dp values
  • Ignoring character constraints in path
Trap Explanation:
PITFALL
  • Candidates may pick node with max dp value incorrectly or ignore character constraints.
Interviewer Note:
CONTEXT
  • Tests ability to interpret DP arrays and relate to graph nodes.
Master "Longest Path With Different Adjacent Characters" in Topological Sort

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Topological Sort Quizzes