Minimum-Cost Root-to-Leaf Path in an N-ary Tree
Updated
Problem statement
Node i has value values[i] and child indices children[i]; root is 0. Path cost is the sum of node values from root through a leaf.
Return a long array containing cost first, followed by the node indices of a minimum-cost root-to-leaf path. Break cost ties lexicographically by index sequence.
Function
minimumCostPath(values: int[], children: int[][]) → long[]Examples
Example 1
values = [5,2,3,1,4]children = [[1,2],[3,4],[],[],[]]return = [8,0,1,3]Path 0,1,3 costs 5+2+1=8, less than the other leaves.
Constraints
1 <= values.length == children.length <= 10^5.- Children form a rooted tree.
More Bloomberg LP Phone Screen questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions
- Minimum Root-to-Leaf Cut CostGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Nonadjacent Sum in a General TreeZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
- Lowest Common Manager for Employee GroupsAmazon · PHONE SCREEN
- File Encryption Tree OptimizationDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Maximum Path Sum Between Marked NodesDoorDash · PHONE SCREENDoorDash interview questions
- Transitive Employee Referral CountsRobinhood · ONSITE INTERVIEWRobinhood interview questions
- Best Sum Downward Tree PathCitadel · OACitadel interview questions