Thread Count (Also for Infra Automation Intern)
Learn this problemProblem statement
There are service_nodes microservices connected by bidirectional edges that form a tree. Edge j connects service_from[j] and service_to[j].
Each microservice has a maximum live-thread value. The values of any two adjacent microservices must differ by exactly 1. Some values were lost, and only k values remain known. Each row [i, value] in currentValues fixes the value of microservice i.
Find the live-thread value for every microservice such that all fixed values and adjacency requirements hold and the total sum of values is as small as possible. A valid solution is guaranteed to exist.
Returns: int[] of length service_nodes, where element i is the live-thread value of microservice i + 1.
Function
findMaximumNumberLiveThreads(service_nodes: int, service_from: int[], service_to: int[], k: int, currentValues: int[][]) → int[]Examples
Example 1
service_nodes = 4service_from = [1, 2, 2]service_to = [2, 3, 4]k = 3currentValues = [[1, 3], [2, 4], [3, 3]]return = [3, 4, 3, 3]There are four microservices and three edges: (1, 2), (2, 3), and (2, 4).
The known values fix nodes 1, 2, and 3 to 3, 4, and 3. Assigning node 4 the value 3 satisfies the required difference of exactly 1 across every edge and minimizes the total. The result is [3, 4, 3, 3].
Constraints
1 ≤ service_nodes ≤ 10^51 ≤ service_from[i], service_to[i] ≤ service_nodes1 ≤ k ≤ service_nodes1 ≤ currentValues[i][0] ≤ service_nodes1 ≤ currentValues[i][1] ≤ 10^6
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026