Nested loops checking every pair. Fails on large inputs — 100k elements = 10 billion ops.
// O(n^2) — brute force two sumfor (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] + arr[j] == target)
return new int[]{i, j};
}
}
// Better: use HashMap for O(n) solution
# O(n^2) — brute force two sumfor i inrange(n):
for j inrange(i + 1, n):
if arr[i] + arr[j] == target:
return [i, j]
# Better: use dict for O(n) solution
O(2ⁿ)Recursive Fibonacci (no memoization)
Each call branches into two more. n=40 takes seconds. n=50 takes minutes. n=100? Heat death of the universe.