FastPrepSum of Scores of Built Arrays
Problems/Sum of Scores of Built Arrays

Sum of Scores of Built Arrays

Uber logoUber● MediumOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given N ranges. Range i goes from low[i] to high[i], both ends included.

You build an array brr of length N. Each brr[i] must be a prime number with low[i] ≤ brr[i] ≤ high[i]. There are usually many different arrays you can build.

The score of an array is the product of all its values. Return the sum of the scores of all the different arrays you can build, modulo 109 + 7. Two arrays are different when they differ at some position, so [2, 3] and [3, 2] count as two arrays when both can be built.

For example, take the ranges [1, 3] and [3, 5]. The first range holds the primes 2 and 3. The second holds 3 and 5. You can build four arrays, with scores 6, 10, 9 and 15. They add up to 40.

Every range holds at least one prime number, and low[i] ≤ high[i] for every i.

Function

sumOfScoresOfBuiltArrays(low: int[], high: int[]) → int

Examples

Example 1

low = [1, 3]high = [3, 5]return = 40

The ranges are [1, 3] and [3, 5]. The first holds the primes 2 and 3. The second holds 3 and 5.

You can build four arrays: [2, 3], [2, 5], [3, 3] and [3, 5]. Their scores are 6, 10, 9 and 15. They add up to 40.

Example 2

low = [1, 1, 2]high = [2, 2, 2]return = 8

The ranges are [1, 2], [1, 2] and [2, 2]. The only prime in each range is 2, so there is just one array to build: [2, 2, 2].

Its score is 2 × 2 × 2 = 8, so the answer is 8.

Example 3

low = [1, 2, 3]high = [4, 5, 30]return = 6350

The ranges are [1, 4], [2, 5] and [3, 30]. Their primes add up to 2 + 3 = 5, 2 + 3 + 5 = 10 and 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 = 127.

Every choice of one prime per range is a different array. The scores of all of them add up to 5 × 10 × 127 = 6350, so the answer is 6350.

Constraints

  • 1 ≤ N ≤ 105, where N is low.length and high.length
  • 1 ≤ low[i] ≤ high[i] ≤ 106 for every i
  • Every range [low[i], high[i]] contains at least one prime number

More Uber interview questions

  • Random Bingo Card GeneratorONSITE INTERVIEW · Seen Dec 2026
  • Travelers per Consecutive City TripletONSITE INTERVIEW · Seen Dec 2026
  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Two Ranked Teams Meeting in a Random BracketOptiver · OAOptiver interview questions
  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
  • Get Triplet CountIBM · OAIBM interview questions
  • Count Fancy NumbersHudson River Trading · OAHudson River Trading interview questions
  • Count Numbers with the Same Set-Bit CountMicrosoft · OAMicrosoft interview questions
  • Count Reverse-Digit PairsVisa · OAVisa interview questions
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
  • Color a Grid with No Monochromatic Row or ColumnIntuit · OAIntuit interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int sumOfScoresOfBuiltArrays(int[] low, int[] high) {
      // write your code here
    }

}
Checking account…