Validate and Resolve Evaluation Chains
Problem statement
Each row of links is [evaluation, target]. A target is either another evaluation name or the literal true or false. Evaluation names are case-sensitive; the two literals are case-insensitive.
Every evaluation must eventually reach one Boolean literal. A duplicate definition, a reference to an undefined evaluation, or a cycle makes the complete input invalid; return ["INVALID"].
Otherwise, return one name:value string for every evaluation, sorted by name.
Function
evaluateChains(links: String[][]) → String[]Examples
Example 1
links = [["E1","E2"],["E2","true"],["E5","false"]]return = ["E1:true","E2:true","E5:false"]E1 follows E2 to true, while E5 is an independent false chain.
Example 2
links = [["A","B"],["B","A"]]return = ["INVALID"]A and B form a cycle.
Example 3
links = [["check","missing"]]return = ["INVALID"]The referenced evaluation has no definition.
Constraints
1 <= links.length <= 10^5.- Names are non-empty ASCII alphanumeric strings and are never the reserved literals.