• 0

Find target subtraction is possible in a given unsorted array of numbers


Problem statment

Given an array of unsorted numbers and a target element.
Find if any two elements subtract to the target element or not.
You can loop through the array only once.
Constraint: Time complexity should be O(n)

Hint : Use map for data stroage


Algorithm

  • While iterating over the array store elements in a map
  • Calculate the current element + target OR current element - target is already in the map or not

Solution