FastPrepSum Multiples of 3, 5, or 7 Below N
Problems/Sum Multiples of 3, 5, or 7 Below N

Sum Multiples of 3, 5, or 7 Below N

Upstart logoUpstart● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source gives the divisor set, strict upper bound, and a concrete example but omits numeric bounds and the return width. The judged core task matches the visible source at about 98%.

Given a positive integer n, return the sum of all positive integers strictly less than n that are divisible by 3, 5, or 7.

Count an integer only once even when it is divisible by more than one of the three divisors.

Function

sumMultiples(n: int) → long

Examples

Example 1

n = 12return = 40

The included integers are 3, 5, 6, 7, 9, 10. Their sum is 40; 12 is excluded because the bound is strict.

Example 2

n = 16return = 81

The included integers are 3, 5, 6, 7, 9, 10, 12, 14, 15. The value 15 is counted once even though both 3 and 5 divide it.

Example 3

n = 3return = 0

No positive integer below 3 is divisible by 3, 5, or 7.

Constraints

  • 1 <= n <= 10^9
  • The result fits in a signed 64-bit integer.

More Upstart problems

  • Babysitter Quote with Hourly RatesONSITE INTERVIEW · Seen Oct 2026
  • Maximum SubarrayONSITE INTERVIEW · Seen Oct 2026
  • Buffet Day GainsOA · Seen Sep 2026
All Upstart interview questionsSee Upstart hiring insights
Saved
class Solution {
    public long sumMultiples(int n) {
        // Write your code here.
    }
}
Checking account…