A buffer with a contract
Buffer [9,4,9,7,4], discard 9, preserve survivor order, reuse storage.
What is specified after the call? Which cells may be ignored?
1 / 11
Buffer [9,4,9,7,4], discard 9, preserve survivor order, reuse storage.
What is specified after the call? Which cells may be ignored?
Copying survivors gives a simple specification.
Repeatedly shifting after deletion moves the same values many times.
Remember only the next accepted-output slot. Why can it never pass the read position?
Before reading r: nums[:w] is the stable survivor sequence from the original prefix.
w <= r protects unread values.
Return w; the tail is unspecified.
[2,4,0,0] + [1,3]
write 4 -> [2,4,0,4]
write 3 -> [2,4,3,4]
write 2 -> [2,2,3,4]
write 1 -> [1,2,3,4]
w = i + j + 1
While j >= 0, w > i. The destination is strictly after unread nums1.
When j < 0, w = i: the untouched prefix is already correct.
AB -> reverse(B) reverse(A) -> B reverse(A) -> BA
Normalize k modulo n only after handling n=0.
nums = [1,0,100]
farthest after index 1 = 1
index 2 is unreachable
Check reachability before using a jump.
[2,3,1,1,4]
0 jumps: end=0
1 jump : end=2
2 jumps: end=4
currentEnd is committed; farthest is under construction.
Majority: unequal votes cancel, under a strict-majority promise.
Unlimited stock trades: profits telescope into adjacent differences, only without transaction costs.
gas=[2,2], cost=[1,1]
Both starts work.
A negative candidate prefix discards a block of starts; a nonnegative total guarantees some start.
Keep at most three duplicates: compare with which accepted position?
Product of [2,0,4] except self: which entry can be nonzero?
Finish with the module quiz.