Skip to main content
change O time based on comments
Source Link

Easiest solution:

  • Put all elements in a hash map -> O(nlognn) to O(n^2) depending on has function
  • Iterate through list doing a lookup for (Sum - A[i]) -> O(n) with O(1) lookups
  • If Sum is 2x A[i], check for second instance value in the map

Solution in O(nlognn) to O(n^2) depending on has function

Easiest solution:

  • Put all elements in a hash map -> O(nlogn)
  • Iterate through list doing a lookup for (Sum - A[i]) -> O(n) with O(1) lookups
  • If Sum is 2x A[i], check for second instance value in the map

Solution in O(nlogn)

Easiest solution:

  • Put all elements in a hash map -> O(n) to O(n^2) depending on has function
  • Iterate through list doing a lookup for (Sum - A[i]) -> O(n) with O(1) lookups
  • If Sum is 2x A[i], check for second instance value in the map

Solution in O(n) to O(n^2) depending on has function

Source Link

Easiest solution:

  • Put all elements in a hash map -> O(nlogn)
  • Iterate through list doing a lookup for (Sum - A[i]) -> O(n) with O(1) lookups
  • If Sum is 2x A[i], check for second instance value in the map

Solution in O(nlogn)