Skip to main content
fix closing code fence
Source Link
Vogel612
  • 25.3k
  • 7
  • 58
  • 141
def squeeze_search(array, target):
    left_index = 0
    right_index = len(array) - 1

    while True:
        right_result = squeeze_right(array, target, left_index, right_index)
        if right_result is not None:
            success, left_index, right_index = right_result
            if success:
                return True
        else:
            return False
        left_result = squeeze_left(array, target, left_index, right_index)
        if left_result is not None:
            success, right_index, left_index = left_result
            if success:
                return True
        else:
            return False


def squeeze_left(array, target, current_index, left_index):
    current_value = array[current_index]
    while left_index < current_index:
        left_value = array[left_index]
        if left_value + current_value == target:
            return (True, current_index, left_index)
        elif left_value + current_value > target:
            return (False, current_index, left_index)

        left_index = left_index + 1

    return None

def squeeze_right(array, target, current_index, right_index):
    current_value = array[current_index]
    while right_index > current_index:
        right_value = array[right_index]
        if right_value + current_value == target:
            return (True, current_index, right_index)
        elif right_value + current_value < target:
            return (False, current_index, right_index)

        right_index = right_index - 1
    return None
```        
def squeeze_search(array, target):
    left_index = 0
    right_index = len(array) - 1

    while True:
        right_result = squeeze_right(array, target, left_index, right_index)
        if right_result is not None:
            success, left_index, right_index = right_result
            if success:
                return True
        else:
            return False
        left_result = squeeze_left(array, target, left_index, right_index)
        if left_result is not None:
            success, right_index, left_index = left_result
            if success:
                return True
        else:
            return False


def squeeze_left(array, target, current_index, left_index):
    current_value = array[current_index]
    while left_index < current_index:
        left_value = array[left_index]
        if left_value + current_value == target:
            return (True, current_index, left_index)
        elif left_value + current_value > target:
            return (False, current_index, left_index)

        left_index = left_index + 1

    return None

def squeeze_right(array, target, current_index, right_index):
    current_value = array[current_index]
    while right_index > current_index:
        right_value = array[right_index]
        if right_value + current_value == target:
            return (True, current_index, right_index)
        elif right_value + current_value < target:
            return (False, current_index, right_index)

        right_index = right_index - 1
    return None
```        
def squeeze_search(array, target):
    left_index = 0
    right_index = len(array) - 1

    while True:
        right_result = squeeze_right(array, target, left_index, right_index)
        if right_result is not None:
            success, left_index, right_index = right_result
            if success:
                return True
        else:
            return False
        left_result = squeeze_left(array, target, left_index, right_index)
        if left_result is not None:
            success, right_index, left_index = left_result
            if success:
                return True
        else:
            return False


def squeeze_left(array, target, current_index, left_index):
    current_value = array[current_index]
    while left_index < current_index:
        left_value = array[left_index]
        if left_value + current_value == target:
            return (True, current_index, left_index)
        elif left_value + current_value > target:
            return (False, current_index, left_index)

        left_index = left_index + 1

    return None

def squeeze_right(array, target, current_index, right_index):
    current_value = array[current_index]
    while right_index > current_index:
        right_value = array[right_index]
        if right_value + current_value == target:
            return (True, current_index, right_index)
        elif right_value + current_value < target:
            return (False, current_index, right_index)

        right_index = right_index - 1
    return None
added 101 characters in body
Source Link
Dan Oberlam
  • 7.9k
  • 2
  • 32
  • 74

A quickly jotted down implementation in Python: - I am quite confident that you can simplify/condense this if you take a few more minutes to do this.

A quickly jotted down implementation in Python:

A quickly jotted down implementation in Python - I am quite confident that you can simplify/condense this if you take a few more minutes to do this.

added 13 characters in body
Source Link
Dan Oberlam
  • 7.9k
  • 2
  • 32
  • 74

A simplequickly jotted down implementation in Python:

A simple implementation in Python:

A quickly jotted down implementation in Python:

edited body
Source Link
Dan Oberlam
  • 7.9k
  • 2
  • 32
  • 74
Loading
edited body
Source Link
Dan Oberlam
  • 7.9k
  • 2
  • 32
  • 74
Loading
Source Link
Dan Oberlam
  • 7.9k
  • 2
  • 32
  • 74
Loading