Solution Review: Nested Loop with Multiplication (Intermediate)
This review provides a detailed analysis of how to solve the "Nested Loop with Multiplication (Intermediate)" problem.
Solution #
Press + to interact
Rust 1.57.0
fn main(){let n = 10;let mut sum = 0;let mut j = 1;let pie = 3.14;for _i in (1..n).step_by(3){ // O(n)println!("{}",pie); // O(n)while j < n { // O(n) * O(log(n))sum += 1; // O(n) * O(log(n))j *= 3; // O(n) * O(log(n))}j = 1; // O(n)}println!("{}",sum);}
-
The outer loop index
i
goes: . That means that the outer loop has iterations. -
The inner loop index
j
goes: . That means that an inner loop has iterations. ...
Statement | Number of Executions |
---|---|
let n = 10; |
|
let mut sum = 0; |
|
let j = 1; |
|
let pie = 3.14; |
|
for _i in (1..n).step_by(3) |
|
println!("{}",pie); |
Access this course and 1400+ top-rated courses and projects.