Skip to content

Two Pointer

def two_pointer_algorithm(arr):
    left = 0
    right = len(arr) - 1

    while left < right:
        # do something with the left and right pointers
        left += 1
        right -= 1

    # do something after the while loop is finished
    return arr