Check all subarrays. For each starting index i and ending index j, compute the sum and check if it equals k.
There are subarrays. Even with prefix sums (making each sum ), the total is .
For , that's operations. Too slow.
The trap
Check all subarrays. For each starting index i and ending index j, compute the sum and check if it equals k.
There are subarrays. Even with prefix sums (making each sum ), the total is .
For , that's operations. Too slow.