def max_consecutive_elements(array_str: str) -> int:
result: int = 0
first_pointer: int = 0
while first_pointer < len(array_str):
second_pointer: int = first_pointer
while second_pointer < len(array_str) \
and array_str[second_pointer] == array_str[first_pointer]:
second_pointer += 1
result = max(result, second_pointer - first_pointer)
first_pointer = second_pointer
return result
def subarray_sum(array: int, x: int) -> bool:
right: int = 0
current_sum: int = 0
for left in range(len(array)):
if left > 0:
current_sum -= array[left - 1]
while right < len(array) and current_sum < x:
current_sum += array[right]
right += 1
if current_sum == x:
return True
return False
def two_sum(arr: list, x: int) -> tuple:
arr.sort()
left: int = 0
right: int = len(arr)-1
while left <= right:
current_sum = arr[left]+arr[right]
if current_sum == x:
return arr[left], arr[right]
if current_sum <x:
left += 1
else:
right -= 1
return None, None
if __name__ == '__main__':
array: int = [5, 7, 9, 12, 15, 18, 19, 20, 22]
x: int = 27
print(two_sum(array, x))
def subarray_sum(array: int, x: int) -> bool:
right: int = 0
current_sum: int = 0
for left in range(len(array)):
if left > 0:
current_sum -= array[left - 1]
while right < len(array) and current_sum < x:
current_sum += array[right]
right += 1
if current_sum == x:
return True
return False