Search⌘ K
AI Features

Solution: Nested Loop With Multiplication (Advanced)

This review provides a detailed analysis of the different ways to solve the nested loop with multiplication challenge.

We'll cover the following...

Solution

Python 3.5
n = 10 # can be anything
sum = 0
pie = 3.14
for var in range(n):
j = 1
while j < var:
sum += 1
j *= 2
print(sum)

In the main function, the outer loop is O(n)O(n) ...