DSA · Big O & problem solving
Count iterations, not lines
An assignment inside a loop runs once per iteration. A loop over n values is O(n), even when its body contains several constant-time statements.
Two loops that run one after another have additive work. Two loops nested over the same n values may inspect every pair and have multiplicative work: O(n × n) = O(n²).