LeetCode – Two Sum

LeetCode – Two Sum- Given an array of integers, find two numbers such that they add up to a specific target number.

This problem i.e. Two Sum is one of the most frequently asked programming question in most interviews especially for a junior level programmer.

Analysis: This problem is pretty straightforward. We can simply examine every possible pair of numbers in this integer array. When the first number is greater than the target, there is no need to find the second number & when the sum of the two numbers match the target we simply break and return the pair of number.

Java Solution:

I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.

Leave a Reply

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