Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

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


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *