Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_array_quadruplet(arr, s):
- #pass # your code goes here
- arr.sort()
- for i in range(len(arr)-3):
- for j in range( i + 1,len(arr) - 2):
- first = arr[i]
- second = arr[j]
- left = j + 1
- right = len(arr) - 1
- target = s - arr[i] - arr[j]
- #value = arr[left] + arr[right] #
- while left < right and arr[left] + arr[right] != target :
- if arr[left] + arr[right] < target:
- left += 1
- else:
- right -= 1
- #if left >= right:
- # break
- #value = arr[left] + arr[right]
- if arr[left] + arr[right] == target:
- return [arr[i],arr[j],arr[left],arr[right]]
- return []
- # arr = [2, 7, 4, 0, 9, 5, 1, 3], s = 20
- # 2, [7, 4, 0, 9, 5, 1, 3], 20 - 2 = 18
Add Comment
Please, Sign In to add comment