2 ms·
Shouldn't the time constraint be around O(n²) for the sorted approach, as you are iterating through the sorted array in a nested loop, resulting in (N - K)/2 *N
by 0xB504 9y ago
Shouldn't the time constraint be around O(n²) for the sorted approach, as you are iterating through the sorted array in a nested loop, resulting in (N - K)/2 *N lookups of pairs? Or am I missing something?
- panic 9y agoThe value of j never decreases, is bounded above by numbers.len(), and increments each time through the inner loop. This means the inner loop can run a maximum of numbers.len() times.