Reported July 2026
Upstartmath

Sum Multiples of 3, 5, or 7 Below N

Reported by candidates from Upstart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Upstart OA. Under 2s to a working solution.
Founder's read

Upstart reported this one in July 2026, and it looks like a warmup until the double-counting bites you. Sum every positive integer below n divisible by 3, 5, or 7, counting each number once. The sample cases are tiny, so a loop passes them and feels fine. Then n hits 10^9 and the loop dies. This is a math problem dressed up as a loop problem, and the pattern is inclusion-exclusion with arithmetic series. If you blank during the live OA, StealthCoder runs invisibly on your desktop and gives you the formula path as a safety net.

The problem

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 = 12
return = 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 = 16
return = 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 = 3
return = 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is inclusion-exclusion. Write a helper that sums multiples of k below n: m = (n-1)/k, then k*m*(m+1)/2. Add the sums for 3, 5, and 7. Subtract the sums for 15, 21, and 35, since those numbers got counted twice. Add back the sum for 105, since multiples of all three were added three times and subtracted three times. That's O(1). The pitfall is the strict bound. Use n-1, not n, or 12 sneaks into Example 1 and you get 52 instead of 40. Second pitfall is overflow. With n near 10^9, k*m*(m+1) can exceed 32 bits, so use 64-bit math everywhere. Check n=3 returns 0 and n=1 returns 0. If you freeze mid-assessment, StealthCoder is the hedge that surfaces this formula while you keep typing.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Sum Multiples of 3, 5, or 7 Below N cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Upstart's OA.

Upstart reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sum Multiples of 3, 5, or 7 Below N FAQ

What's the trick in the Upstart sum of multiples problem?+

Inclusion-exclusion over the divisors 3, 5, and 7. Sum each divisor's multiples with the arithmetic series formula, subtract the pairwise overlaps (15, 21, 35), then add back the triple overlap (105). No loop needed, so it runs in constant time.

Why does the brute force loop fail?+

The constraint allows n up to 10^9. A loop from 1 to n does a billion iterations with modulo checks, which is risky for a time limit. It passes the small examples, which is exactly why people trust it and then fail the hidden large cases.

What edge cases should I test?+

Test n=1, n=3 (expect 0), and n=12 (expect 40) to confirm the strict upper bound. Test n=16 (expect 81) to confirm 15 is counted once. Also test n=10^9 to make sure your arithmetic uses 64-bit integers and doesn't overflow.

How do I get the count of multiples below n?+

Use (n-1)/k with integer division. That gives the number of positive multiples of k strictly less than n. Then the sum is k times m times (m+1) divided by 2, where m is that count. Using n instead of n-1 breaks cases where n itself is a multiple.

How do I prepare for this in 48 hours?+

Practice writing the sum-of-multiples helper from memory and the inclusion-exclusion signs: plus singles, minus pairs, plus the triple. Then run it on the three examples by hand. Spend the rest of your time on other math-flavored warmups, since this style of problem shows up often.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Upstart.

OA at Upstart?
Invisible during screen share
Get it