LeetCode 167. Two Sum II - Input array is sorted [Algorithm + Code Explained ]

preview_player
Показать описание
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.

LeetCode : Two Sum II - Input array is sorted

Question - Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

Note : Your returned answers (both index1 and index2) are not zero-based.

Example:
Input: numbers = [2,7,11,15], target = 9
Output: [1,2]
Explanation: The sum of 2 and 7 is 9. Therefore index1 = 1, index2 = 2.

Рекомендации по теме
Комментарии
Автор

That slide was very useful. Appreciate the effort

sriram
Автор

Can you PLEASEEE do " 3Sum" - LeetCode 15 @ jayati tiwari

itachicodes
Автор

I really appreciate the way you explained, I would suggest that you make more videos about Java Data Structure or Algorithm. It will really help us.

learnhome
Автор

good choice to use two pointers method! Thank you!

danqingreader
Автор

if result [] size is 2, then is it wrong to write while (left<=right) ? the ans was acceptable but just to be sure

cinemafellaz
Автор

Thank you for the video. Can we get O(LogN) complexity since the array is sorted?

hemaladani
join shbcf.ru