Skip to content

Instantly share code, notes, and snippets.

@IlyaDonskikh
Last active August 13, 2019 14:22
Show Gist options
  • Save IlyaDonskikh/54ed3e0945ac190eade28a77a7c0fcfb to your computer and use it in GitHub Desktop.
Save IlyaDonskikh/54ed3e0945ac190eade28a77a7c0fcfb to your computer and use it in GitHub Desktop.
arr = [2, 4, 5, 5, 8, 9, 11, 13]
t = 14
min_index = 0
max_index = arr.length - 1
success = false
while (min_index != max_index) && !success do
sum = arr[min_index] + arr[max_index]
if sum > t
max_index -= 1
elsif sum < t
min_index += 1
else
success = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment