Sum Skipping Multiples of 5 or 7
Updated
Problem statement
Given a positive integer n, return the sum of all integers from 1 to n, skipping every number that is divisible by 5 or by 7.
Both 1 and n are part of the range.
Function
filteredIntegerSum(n: int) → longExamples
Example 1
n = 10return = 33The included values are 1, 2, 3, 4, 6, 8, 9, whose sum is 33.
Example 2
n = 1return = 1The range holds only 1, which is not divisible by 5 or 7, so the sum is 1.
Example 3
n = 35return = 420Start from the sum 1 + ... + 35 = 630. Remove the multiples of 5 and 7, then add 35 back once because it was removed twice, leaving 420.
Constraints
1 <= n <= 10^9- The answer fits in a signed 64-bit integer.
More Bank of America Online Assessment questions
- Return Exact Cash Register ChangeOA · Seen Aug 2026
- Sum Skipping Multiples of 7OA · Seen Nov 2025
- Wildcard Substring MatchOA · Seen Nov 2025
- Maximum String BeautyOA · Seen Sep 2024
- Merge Point of Two Linked ListsOA · Seen Oct 2023
- Remove Duplicates from a ListOA · Seen Oct 2023
- Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
- Count Level-Order Traversals of a TreeOA · Seen Sep 2023
- Count Set BitsOA · Seen Sep 2023
- Count Pairs with Sum KOA · Seen Jun 2023
Similar questions at other companies
- Summarize Taxi Drivers and RidesBoston Consulting Group · OABoston Consulting Group interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count Valid Square PairsAuxoAI · OA
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Digit-Sum Sequence Join PointOpenAI · OAOpenAI interview questions