...

/

Solution: Nested Loop with Multiplication (Basic)

Solution: Nested Loop with Multiplication (Basic)

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

We'll cover the following...

Solution #

Press + to interact
n = 10 # n can be anything, this is just an example
sum = 0
pie = 3.14
var = 1
while var < n:
print(pie)
for j in range(1, n, 2):
sum += 1
var *= 3
print(sum)

Time Complexity

The outer loop in this problem, i.e., everything under line 5, while var < n runs log3(n)log_3(n) times since var will first be equal to 11, then ...

Access this course and 1400+ top-rated courses and projects.