Two Sum | 2 Sum leetcode | Leetcode 1| Array HashMap | Google Amazon Facebook Microsoft Apple

preview_player
Показать описание

Subscribe for more educational videos on data structure, algorithms and coding interviews.

Popular Playlists:

Follow me on -

#Array #HashMap #Easy #Coding #Programming #TwoSum #Interview #Practice #Leetcode #Problem_1 #Algorithm #Java #Preparation
Рекомендации по теме
Комментарии
Автор

Hello, for your last example, why did you place the map.put(nums[i], i); after the if statement? Doesn't the map need to be populated before the if statement can properly carry out its operations since it's trying to complete operations based off of a populated map?

shayzhao
Автор

Hello, thanks for sharing the two solutions. However I don't agree on the complexity of the second one. Indeed, why didn't you include in the complexity estimation the one generated by map.contains method which should have o(n). Then the general complexity of the loop will be o(n²). Am I wrong ?
Thank you

ac_mafr__
Автор

following your interview playlist of top interview question :) day-1

animepoll
Автор

I have a doubt ? How it will work for duplicate numbers by using map since key doesn't allow duplicate. For eg., [3, 2, 3] and target is 6. Could someone explain ?

deepakg
Автор

Line 3: Char 32: error: expected ')'
public: int[] twoSum (int[] nums, int target)
^
Line 3: Char 25: note: to match this '('
public: int[] twoSum (int[] nums, int target)
^



I wrote the same code-
class Solution {

public: int[] twoSum (int[] nums, int target)
{

for(int i=0;i<sizeof(nums);i++)

for(int j=i+1;j<sizeof(nums);j++)

if(nums[i]+nums[j]==target)

return new int[] {i, j};




return new int[2];
}
};

tiGeR__-rs
Автор

Thanks for this tutorial. Can you explain why we need to change the array length to n-1 on the first loop then n+1 on the nested loop?

rob
Автор

Why the last return new int[2]? Can someone explain me pls?

TiagoDaniel
Автор

what does it mean i!=map.get(target-num[i]) ??

shashanksingh
Автор

Is there a reason why this is not O(1) time complexity? It appears that the length of the nums array is constant, and since we're traversing that constant, would it be O(1)?

vrishabsathish
Автор

if this is "Easy" im gonna have a very hard time lol

shiestypooo
visit shbcf.ru