Files
java-interview-lab/sliding-window/output/05-two-pointers-trace.txt
T

22 lines
964 B
Plaintext

Opposite-end two pointers
=========================
Two Sum II: sorted [1, 3, 4, 6, 8, 11], target 10
lo=0 hi=5 1 + 11 = 12 > 10 hi--
lo=0 hi=4 1 + 8 = 9 < 10 lo++
lo=1 hi=4 3 + 8 = 11 > 10 hi--
lo=1 hi=3 3 + 6 = 9 < 10 lo++
lo=2 hi=3 4 + 6 = 10 == 10 found
answer = indices [2, 3]
Container With Most Water: heights [1, 8, 6, 2, 5, 4, 8, 3, 7]
lo=0 hi=8 min(1,7) x 8 = 8 best=8 lo++ (left line is shorter)
lo=1 hi=8 min(8,7) x 7 = 49 best=49 hi-- (right line is not taller)
lo=1 hi=7 min(8,3) x 6 = 18 best=49 hi-- (right line is not taller)
lo=1 hi=6 min(8,8) x 5 = 40 best=49 hi-- (right line is not taller)
lo=1 hi=5 min(8,4) x 4 = 16 best=49 hi-- (right line is not taller)
lo=1 hi=4 min(8,5) x 3 = 15 best=49 hi-- (right line is not taller)
lo=1 hi=3 min(8,2) x 2 = 4 best=49 hi-- (right line is not taller)
lo=1 hi=2 min(8,6) x 1 = 6 best=49 hi-- (right line is not taller)
answer = 49