sumOfMultiples

Easy · Loops and Iterations · 3 test cases

Find the sum of all the multiples of 3 or 5 below a given number. For example, if the number is 10, the multiples are 3, 5, 6 and 9. The sum is 23.

Examples

sumOfMultiples(10) → 23
sumOfMultiples(1000) → 233168

Starter code

function sumOfMultiples(number) {

}

Complexity of the optimal solution

Time O(n), space O(1). The function uses a single loop that runs from 1 up to the given number (n). This makes the time complexity linear. The space used for the sum variable is constant.

Solve sumOfMultiples in the browser