Prime Tree City Labelings
Updated
Problem statement
Hackerland contains n cities numbered from 1 to n. Its n - 1 roads form a tree, where road i connects edgeFrom[i] and edgeTo[i].
Assign one prime number from 2 through 100, inclusive, to every city. Prime values may be reused. For every road, the sum of the prime values assigned to its two endpoints must not be prime.
Return the number of valid assignments modulo 10^9 + 7.
Function
countPrimeLabelings(n: int, edgeFrom: int[], edgeTo: int[]) → intExamples
Example 1
n = 2edgeFrom = [1]edgeTo = [2]return = 609Among all ordered assignments of primes from 2 through 100 to the two cities, 609 have a non-prime endpoint sum.
Example 2
n = 1edgeFrom = []edgeTo = []return = 25There are 25 primes from 2 through 100, and a one-city tree has no road constraint.
Constraints
1 <= n <= 200000edgeFrom.length = edgeTo.length = n - 1- The roads form a tree.
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Count Distinct Binary Search TreesC3.ai · OAC3.ai interview questions
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Part 2: Batch Access ReviewScale AI · OAScale AI interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Binary Tree CamerasAmazon · OA · PHONE SCREEN
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Profitable Currency Exchange CycleOptiver · OAOptiver interview questions
- Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
- Maximum Sum Path Between Two Leaf NodesGoogle · OAGoogle interview questions
Rippling interview experiences
- Rippling Senior SWE Full Loop Questions: 1 Experience
- Rippling Experienced SWE Phone Screens: 2 Experiences
- Rippling Design Rounds and Onsites: 17 Experiences (Part 3 of 3)
- Rippling Phone Coding Screens: 14 Experiences (Part 2 of 3)
- Rippling SWE Screens and Loops: 31 Experiences (Part 1 of 3)
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)