561.Count Iterations of Consecutive Loops
Easy
A function runs three loops one after another: one over
n, one over m, and another over n. Given n and m, return the total number of loop passes.
When loops are sequentialSequential CodeStatements or loops that run one after another, not inside each other., their work adds up: n + m + n = 2n + m, which is O(n + m). Contrast this with nested loops, where counts multiply. Telling "one after another" from "one inside another" is most of the skill in reading complexity from code.
Example 1:
Input: n = 3, m = 5
Output: 11
Example 2:
Input: n = 0, m = 4
Output: 4
+ 4 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ n, m ≤ 1000000
n =
3
m =
5