Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6EqSkUWKNBc8i3Q3U
25 lines
1.1 KiB
Plaintext
25 lines
1.1 KiB
Plaintext
Operation counts, brute force vs window / two pointers (counted, not timed)
|
|
===========================================================================
|
|
|
|
Max sum of k=100 consecutive elements: element reads
|
|
n brute force sliding window ratio
|
|
1000 90,100 1,900 47.4x
|
|
2000 190,100 3,900 48.7x
|
|
4000 390,100 7,900 49.4x
|
|
8000 790,100 15,900 49.7x
|
|
|
|
Pair search, target absent (worst case) in a sorted array 0..n-1: checks / steps
|
|
n all pairs two pointers
|
|
1000 499,500 999
|
|
2000 1,999,000 1,999
|
|
4000 7,998,000 3,999
|
|
8000 31,996,000 7,999
|
|
|
|
minWindow on random strings over A-D, t="ABCD" (seed 42): pointer moves
|
|
The loop is nested but each pointer only moves forward, so total moves stay linear.
|
|
n right moves left moves valid windows
|
|
1000 1,000 996 996
|
|
2000 2,000 1,996 1,996
|
|
4000 4,000 3,996 3,996
|
|
8000 8,000 7,993 7,993
|