class NestedLoop {
public static void main(String[] args) {
int n = 5; // 1 step
int m = 7; // 1 step
int sum = 0; // 1 step
for (int i = 0; i < n; i++) { // n steps
for (int j = 0; j < m; j++) { // nm steps
sum++; // nm steps
}
}
System.out.println("Sum: " + sum); // 1 step
}
}
how it is came 1+1+1+6n+4+n(6m+4)+3nm+2… (6n+4)…
Course: Data Structures for Coding Interviews in Java - Learn Interactively
Lesson: Example: Time Complexity of an Algorithm With Nested Loops