def special_nodes(tree_nodes: int, tree_from: list[int], tree_to: list[int]) -> list[int]:
Online assessment, problem 3 of 3. Citadel's 90-minute HackerRank assessment (three coding problems) ends with a tree problem. Three candidates reported it:
A tree has tree_nodes nodes numbered 1..tree_nodes and tree_nodes - 1 edges given as two arrays: edge i connects tree_from[i] and tree_to[i]. Every edge has length 1. Return a list of length tree_nodes whose k-th value is 1 if node k + 1 is special and 0 if it is not.
A node is special if it is an end of a longest path in the tree. When several paths tie for longest, a node is special if it ends any of them.
The function name, the parameter names, the numbering from 1 and the 1/0 output are ours; the reports give none of them.
special_nodes(5, [1, 1, 1, 1], [2, 3, 4, 5]) -> [0, 1, 1, 1, 1]
Node 1 is the centre of a star. Every longest path has length 2 and runs leaf, 1, leaf, so each leaf ends one and node 1 ends none.
Three candidates report this as the last of three problems in Citadel's 90-minute HackerRank assessment, which is coding only. The other two are usually a palindromic-substrings count and a token-expiry simulation, each with its own page; one candidate remembers the second only as array processing. One candidate calls the assessment not hard; another solved all three problems in about half an hour and moved on to the next round. A reply notes that the assessment seems to reuse the same problems. No input sizes were reported.
Online assessment, problem 3 of 3. Citadel's 90-minute HackerRank assessment (three coding problems) ends with a tree problem. Three candidates reported it:
A tree has tree_nodes nodes numbered 1..tree_nodes and tree_nodes - 1 edges given as two arrays: edge i connects tree_from[i] and tree_to[i]. Every edge has length 1. Return a list of length tree_nodes whose k-th value is 1 if node k + 1 is special and 0 if it is not.
A node is special if it is an end of a longest path in the tree. When several paths tie for longest, a node is special if it ends any of them.
The function name, the parameter names, the numbering from 1 and the 1/0 output are ours; the reports give none of them.
special_nodes(5, [1, 1, 1, 1], [2, 3, 4, 5]) -> [0, 1, 1, 1, 1]
Node 1 is the centre of a star. Every longest path has length 2 and runs leaf, 1, leaf, so each leaf ends one and node 1 ends none.
What passers do: One candidate solved all three assessment problems, this one included, in about half an hour and moved on to the next round
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.