FastPrepPrime Tree City Labelings
Problems/Prime Tree City Labelings

Prime Tree City Labelings

Rippling logoRippling● HardOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a detailed real Rippling OA prompt. The report directly provides the tree model, reusable prime labels from 2 through 100, non-prime edge-sum rule, modulus, and the two-city answer 609. Estimated match rate: 95-98% for the judged task. The report did not provide numeric limits or an exact function signature.

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[]) → int

Examples

Example 1

n = 2edgeFrom = [1]edgeTo = [2]return = 609

Among 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 = 25

There are 25 primes from 2 through 100, and a one-city tree has no road constraint.

Constraints

  • 1 <= n <= 200000
  • edgeFrom.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)
All Rippling interview questionsSee Rippling hiring insights
Saved
class Solution {
    public int countPrimeLabelings(int n, int[] edgeFrom, int[] edgeTo) {
      // write your code here
    }

}
Checking account…