I need to validate correctness, but this is brilliant! By only resetting either `min_idx` or `max_idx`, depending on the comparison of the current and last keys, I am seeing an order of magnitude speed-up for larger haystacks and needles.