@take U forward : Hi Striver Bhaiya , I love your video , I am learning alot from you , just want to highlight in SDE sheet for this problem it's redirecting to some other question (i.e Find all pairs with a given sum) ,but it's similiar to 2sum approach only :)
@RamanKumar-er8ie Жыл бұрын
it does not work on tc=-3,-2,2,3,3 any please help me out in this
@abhinavennala9613 Жыл бұрын
@@RamanKumar-er8ie what is the target?
@habeeblaimusa4466 Жыл бұрын
Bro, I am a guy from Africa you are the first person in this tech community that inspires me that I can do it.. Hats off for you bro 🔥🔥🔥
@kushalchakraborty6970 Жыл бұрын
Bro ,I need some tips to increase my 🍆?
@kulkarnisoham Жыл бұрын
That's a complement to whole country..!!
@Fe-ironman10 ай бұрын
no@@kulkarnisoham
@barnam_das8 ай бұрын
yes my boy, you can do it lets gooooo !!!!
@ArvindSingh-wj7vy7 ай бұрын
Thank you from India on behalf of Striver 😂
@TheITEngineer2 ай бұрын
Striver, I cracked my coding interview by providing your optimal solution. Can’t thank you enough. You have changed lives of many. Keep doing great work ❤
@Pai5566la2 ай бұрын
Bro, can you say about your complete interview experience
@dhruvbudhwani7599Ай бұрын
Don't lie 😅
@shifteditz06Ай бұрын
where, which company, how much lpa?
@kushagrakulshrestha2966Ай бұрын
dont play games with us man
@pragmaticcoder6910 Жыл бұрын
I can’t thank enough because you teach so well about the concepts of DSA compared to others. None of the paid resources out there have good content. All I can say is May God bless you with long life and happiness. You are making all of us to land in our dream job.
@many987 Жыл бұрын
bhaiya you're so much doing for us, even you live alone in Poland, you sacrifice your time for you and I understand every thing you teach as you are so good in explaining and making people understand. once again thanks a lot for this
@suravighosal9934 Жыл бұрын
We need more problem solving videos. Explanation is super. I have gone through a few channels but this is the best! Thank you so much.❤️
@09ankurjaiswal85 Жыл бұрын
00:06 The video covers the 'two sum problem' and its two varieties. 02:04 Two sum problem can be solved using brute force method 04:05 Optimizing 2 Sum problem using a better solution 06:08 Using hashing to easily retrieve elements from a data structure. 08:13 Find the indexes of two elements in an array 10:30 Two pointer approach is a slightly better solution to solve the problem without using a map data structure. 12:38 Using the two-sum problem to find pairs that add up to a given target 14:51 The time complexity of the algorithm is O(n) 16:49 Space complexity and array manipulation explanation
@KP-we9ce10 ай бұрын
@takeUforward
@manideep71484 ай бұрын
@takeUforward
@Josuke2174 ай бұрын
Man after watching the first 5 videos and solving the problems on my own , I was also able to solve almost all medium and some hard problems. Watching these videos really built my logic , these lectures are a gold mine.
@Josuke2174 ай бұрын
I didn't think about hashing but you mentioned it, I quickly coded it and got the answer. Now I just have to think of these approaches quickly
@Squirt_Turtle4 ай бұрын
Yes even i can solve any problem using brute force approach for better & optimal i have to think....i m sure till the course end i will able to improve my solving skills..i belive ❤
@KrishnaKumar-b4m9p2 ай бұрын
@@Josuke217 same
@aryansinha1818 Жыл бұрын
Man you have changed a lot, this new version feels like a super saiyan mode.
@takeUforward Жыл бұрын
Haha, experience :)
@harshavardhan184 Жыл бұрын
This is the consistency we need from you bhai! 🔥
@52_it_rohitmukherjee99 Жыл бұрын
He is just insane🔥
@secretcoder7 Жыл бұрын
GREAT BHAIYA I buy multiple dsa courses but i only understand with ur lectures 🤗🤗
@itzmartin20 Жыл бұрын
Understood! Thanks a billion for your top-notch explaination brother!
@md.ualiurrahmanrahat2400 Жыл бұрын
Done this video. Amazing explanation. Learning amazing. Growing amazingly.
@parakhpatel9311 ай бұрын
this 5-star add is just crazy!!
@parthkolgiri7501 Жыл бұрын
When he introduced two pointer method my mind was like 🤯💥 Thank you striver!!!
@AbjSir Жыл бұрын
2 pointer approach was very beautiful
@yashwanthostwal6947 Жыл бұрын
int main() {int n=3; int array[3]={3,2,4}; int target=6; for(int i=0; i
@KomalSingh-qr4mu3 ай бұрын
Understood ! This is the first ques of my challenge 😃
@PrithaMajumder6 ай бұрын
Raj, Thanks a lot for This Amazing Video about C++ Arrays Video - 5 Completed ✅
@JatinderDhiman-e4c9 ай бұрын
The question is to find the indices of the elements which on adding give us the target value. In the last part of video, where we need to find the solution in O(1) space, we sort the array and hence lose the indices of input array. So how can we return the indices of elements then ?
@alwin3000zАй бұрын
When I was asked before. I first sorted the array and done the binary search instead of hashmap to find the target. Wish i saw ur video then.
@tanmaykarn Жыл бұрын
goddamn, maybe it was the first time, I understood the approach from the video and coded it on my own and got it accepted. God complex bruhh
@hareshnayak73028 ай бұрын
Understood, Thank you strivers for this amazing video.
@BuragapuHaritha4 ай бұрын
I am actually preparing for my placements,now im btech 3 rd yr and i wanted someone who says from the scratch with the bestttttttt explanation.........thankyou soo muchh bro...i will follow each and every video of urs and i hope i can crack it....!!!
@PavitraYakkali2 ай бұрын
if you submit this two pointer approach in leet code is it accepted??
@sagestudy Жыл бұрын
You are Great Sir! I love your explanation !!
@nihalshaikh1968 ай бұрын
Using unordered_map we can do it in O(n) and even if we use ordered map we can do it in O(n*logn) and for two pointer approach we are sorting first so it is taking O(n*logn) so how is that optimal approach?
@arpit32425 ай бұрын
Two pointer approach is not that much optimal approach, but it is used when we want to find the answer without "map" data structure.
@m_fi89263 ай бұрын
in the brute force approach you should have initialized j=i+1;
@sagnikbose5823 Жыл бұрын
Bhaiya thanks for understanding from the student perspective. You are doing a really great job. Looking forward to the other problem solving videos from you. Good luck!
@movocode4 ай бұрын
10:36 mpp.insert({nums[i], i}); is more optimised than mpp[num] = i; (used in video)
@lofiboy7866Ай бұрын
Explain why
@harshukey6072 Жыл бұрын
Understood 🎉 40 lakh
@HassanAbbas-wy7wj3 ай бұрын
love you striver😍 you are the best teacher and mentor
@sunilkamat8199 Жыл бұрын
Brute -> Better > Optimal = BEST👌
@anamikarawat3698 Жыл бұрын
Thankss bhaiya for this consistency ❤️🙌 My placement is coming soon I'm in 6th semester!!🙂
@legendrose6828 Жыл бұрын
me too, can we connect on linkedin?
@jayrathod7957 Жыл бұрын
Hello bhaiya how was it? I'm here at 3rd sem 🤔
@chiragdusad20158 ай бұрын
Hey! Do you get the placements or how was your experience?
@harshitrautela658510 ай бұрын
🎯 Key Takeaways for quick navigation: 00:45 📚 *The video is part of the Striver's A to Z DSA course, covering comprehensive content with a guarantee of deep understanding in DS algo for interviews worldwide.* 01:12 🎯 *The Two Sum problem has two varieties: one asks for a yes or no if a pair with the given sum exists, and the other requires returning the indices of the pair.* 02:50 🧠 *The initial Brute Force solution involves nested loops to check every pair's sum.* 05:24 ⏩ *The improved solution uses hashing, mapping array elements to their indices, reducing time complexity to O(n).* 09:17 🚀 *The optimal approach, sorting the array and using two pointers, achieves O(n log n) time complexity without extra space.* 15:16 🔄 *The space complexity for the two-pointer approach is O(1), considering no additional space is used.* 17:50 📂 *Code for all three approaches (Brute Force, Hashing, Two-Pointer) is available in C++, Java, and Python in the video description.* Made with HARPA AI
@charuwaka18 ай бұрын
3:33 here you can keep j=i+1 instead of 0 so you don' need to write i==j
@sreescorner Жыл бұрын
Thanks a lot, very clear explanation
@saddatsabanature43077 ай бұрын
solve in python $$$ x=list(map(int,input().split())) x.sort() y=int(input()) for i in range(y): a=(y-x[i]) if (a in x): p=x.index(a) print(i,p) break else: continue time complexity 0(n)
@shafiulhaque6583 Жыл бұрын
Thanks to you for the video Sir . Had a query : In Type 2 of the problem , why do we need the extra Data structure for the indices ? Because I think "left" and "right" these should be giving us the indices of the 2 numbers whose sum equals to the target .
@aashishomre1624 Жыл бұрын
Aftet sorting indices are changed
@himanshukaushik9223 Жыл бұрын
@@aashishomre1624 bhai return hum curly braces ma kyu nahi kar sakta hai
@aashishomre1624 Жыл бұрын
Bcoz return type function ka vector hai {-1,-1} indicating no pair found
@aashishomre1624 Жыл бұрын
vector vect{ 10, 20, 30 }; this syntax is used
@cinime Жыл бұрын
Understood! Super awesome explanation as always, thank you very very much for your effort!!
@KritiYadavcodingАй бұрын
feeling sleepy but how can I sleep by taking those open eye dreams at stack ...long way but internal believe
@RahulUnscripted_5 ай бұрын
Can anyone pls explain why it is checked whether remaining is not equal to mp.end() 👀👀
@tamilmukbang37897 ай бұрын
understood. Thank youuuu
@soumyadeepchatterjee21896 ай бұрын
For the 2 pointer approach, if we are sorting the array it is changing the original indexex. So, it is giving a error in LeetCode.
@rhapsody4025 Жыл бұрын
12:36 sorting the array itself will take O(n*n) then another O(n) for the 2 pointer traverssal whick adds up to O(n*n) ruining the whole point of optimisation !
@venkatesh_kens Жыл бұрын
No bro when we sort using bubble sort or selection sort or insertion sort we will get O(n*2) but if we use MERGE SORT or QUICK SORT we will end up with O(N*log(N)) that’s what he is saying to do
@venkatesh_kens Жыл бұрын
But in this question we need to use only QUICK SORT but not MERGE SORT becoz MERGE SORT space complexity is O(N) but for Quick Sort it is O(1)
@venkatesh_kens Жыл бұрын
And you can see him saying it at 16:51
@balajik73767 ай бұрын
Got the same doubt
@balajik73767 ай бұрын
@@venkatesh_kensyou cleared it thanks❤
@Manipinnaka3 ай бұрын
i got an small logic striver not so optimal for(int i = 0; i < nums.length; i++) { for(int j = i + 1; j < nums.length; j++) { if(target-(nums[i]+nums[j])==0){ return new int[]{i,j}; array:[8,4,6,12[ } ex: target =14 14-(8+4)=!0x 14-(8+6)=0 true so we wil return the indexes
@arunimachakraborty1175 Жыл бұрын
Awesome explanation, thanks a lot
@SigmaEditsbr8 ай бұрын
Thanks sir for provide us this type of content ❤❤❤
@HimanshuChamoli-j2vАй бұрын
In the better solution how can you find in the map that array element is present or not untill you put those all the elements in the hash map
@Manas-jj6xfАй бұрын
In which lecture, do you explain the greedy approach for the first time?
@chidambarjoshi3470 Жыл бұрын
I did not understand why you did mpp[a]=i at the last in the type-1 problem
@sayakghosh5104 Жыл бұрын
Understood!!!...Great as always. :)
@poojadasari8140 Жыл бұрын
Understood. Very clear explanation
@kapilraivines84867 ай бұрын
Hey Striver I am from Jupiter... I love your DSA playlist
@nagame859 Жыл бұрын
Top notch 🤩. Understood
@Nishantkumar-oh9th Жыл бұрын
HE just killed it as it says🤗
@RamanKumar-er8ie Жыл бұрын
it does not work on tc=-3,-2,2,3,3 any please help me out in this
@yashicagarg6365 Жыл бұрын
Can we do this using recursion like picking up the index and not picking....please share the code for it.
@27-Joshna11 ай бұрын
even im looking for that solution
@jay8118 Жыл бұрын
Job ke saath saath Padhana koi inse sikhe..🙌🙌
@2Roshan910 ай бұрын
I am starting leetcode from 1st January 2024 1st problem two sums
@prashantindurkar14572 ай бұрын
Top notch . Understood
@DeepakKumar-xj4ul8 ай бұрын
understood everything Thanks a lot sir!
@zameeralucknowi872 Жыл бұрын
Thank u soo much Dada, u r the real inspiration. Respect++;
@ybs383 Жыл бұрын
The Last Optimal Solution of Sorting an array and using two pointer technique will be difficult to use if Array is not Sorted and I have been told to return index of the pairs.
@bhavyasharma3500 Жыл бұрын
Hats off to you striver bro
@ronakparjapati22646 ай бұрын
bhaiya Third approach will not be apply if we return index of both element because if we do sort the element then automatically element indexes will be changed...
@shubhamlipane8634 Жыл бұрын
Understood Thank You :-)
@devil_m_00695 ай бұрын
while (left
@user-zn3be9ik1x Жыл бұрын
Pls make videos on sliding windows types questions and the types
@princepal9930 Жыл бұрын
Yes
@AtulPal9 ай бұрын
I am still looking for hash function, which can work for similar values. example : input array contains : [ 1 1 1 1 1 1 4 1 1 1 1 1 7 1 1 1 1 ] where some constant number of value are other integers and mostly all values are same. in other ways: BigOh (n - c) values are similar and number of different values are "c" constant # of values as we can see above input array as example. If anyone have understood the problem, please share your thought, I will highly appreciated. I know the problem with Hashing is collisions, and find will take BigOh(n) for above example. Can anyone help me to find the solution??
@arshpuri30792 ай бұрын
i am having trouble in understanding that when we declare a map how can we immediately start finding elements in it without filling in the values
@reshmah14972 ай бұрын
Only after filling the map as we iterate on the array, we can find elements.
@lifehustlers164 Жыл бұрын
Completed 5/28!!!
@mohithvaishnav4317 Жыл бұрын
you jus make things easier..
@kingbadshah45210 ай бұрын
understood everything .... thanks striver
@AbhishekSingh-cg3fx13 сағат бұрын
video mai jo code likha hai usme map initialize kese ho rha hai 10:36 p?
@samuelfrank1369 Жыл бұрын
Understood. Thanks a lot. Make More videos please......
@ExpoDev_Dash Жыл бұрын
for optimal solution why cant we return the pointer values as indexs ?? for variety 2
@saumitrapandey3070 Жыл бұрын
because after sorting the array indexes are changed
@banothutharun27438 ай бұрын
understood sir
@samlinus836 Жыл бұрын
As usual you rock as you explain 🔥 Hey Raj, what if the array has duplicate elements for example, arr = [2,3,5,1,2] and target = 4 Will hashing work for this case too?.................Because hashmap has unique keys
@ayushmittal9666 Жыл бұрын
Yes it will work beacuse we will check if the target - curr is present in the hashmap before putting the curr in map , So if the curr elem is duplicate of some element that is previiously present, we wont have to worry coz we are checking before inserting .
@samlinus836 Жыл бұрын
@@ayushmittal9666 Understood thanks
@AnjuGupta-sz1uk Жыл бұрын
understood bhaiya! really well explained..
@HARSHRAJ-gp6ve4 ай бұрын
Raj bhaiya, if we apply binary search for I+1 to aaray size for every I it also give result in nlogn
@kushagrakulshrestha2966Ай бұрын
cAN two pointer approach work for finding sum and printing index or only hashing will work there ?
@girdhar32243 ай бұрын
can we do binary search and improve on approach
@GurpreetSingh-pv2vv5 ай бұрын
what if array contain duplicate element :(
@ayushagrawal205 Жыл бұрын
can we use binary search for required value in both variety ?tc-nlogn.......
@SAGARSINGH-ej4rj Жыл бұрын
def two(): nums = [3, 3] target = 6 dic = {} for i, v in enumerate(nums): dic[v] = i nums.sort() left = 0 right = len(nums) - 1 iteration = len(nums) - 1 for _ in range(iteration): if nums[left] + nums[right] == target: if dic[nums[left]] == dic[nums[right]]: a = dic[nums[left]] dic.pop(nums[left]) b = dic[nums[right]] return a, b else: return left, right elif nums[left] + nums[right] > target: right -= 1 elif nums[left] + nums[right] < target: left += 1 print(two()) Hello! Bro I am getting problem in line 22 while popping the key[3] with value (0, 1), Because its a test case of num = [3, 3] and target = 6. So, while in a dictionary when we remove a key it removes all the matching keys. Try to give us the solution with this test case --> nums = [3, 3] and Target = 6 👈🏻👈🏻 👆🏻👆🏻👆🏻👆🏻 This is my only request, Don't get frustate with my code just plz resolve this test case with your Opinion and Logic.🙏🏻🙏🏻 Please..
@karamveeryadav88246 ай бұрын
00:06 The video covers the 'two sum problem' and its two varieties. 02:04 Two sum problem can be solved using brute force method 04:05 Optimizing 2 Sum problem using a better solution 06:08 Using hashing to easily retrieve elements from a data structure. 08:13 Find the indexes of two elements in an array 10:30 Two pointer approach is a slightly better solution to solve the problem without using a map data structure. 12:38 Using the two-sum problem to find pairs that add up to a given target 14:51 The time complexity of the algorithm is O(n) 16:49 Space complexity and array manipulation explanation Crafted by Merlin AI.
@PulkitBhardwaj-ll2cf4 ай бұрын
Take a look at my solution.. with time complexity O(n) and space complexity O(1).. int n=nums.size(); int i=0,j=1; while(j
@m.nirupreddy8001 Жыл бұрын
Understood! great explanation
@DK-ox7ze Жыл бұрын
Average and worst csse TC of unordered Hashmap is O(1) and O(N), so total TC can be O(N) or O(N^2). So how did you arrive at total TC of O(NlogN) for the better approach?
@lakshitamanie85 Жыл бұрын
Sir has suggested to take ordered_map which has TC = O(logN) for search and insertion instead of unordered_map in case we are given with critical inputs or when problem might end up to worst case.
@thesalahrand Жыл бұрын
Understood
@TrinmoyDutta Жыл бұрын
how the time complexity is O(n), sorting also has a time complexity, please explain
@ShravanKumar-wg9pv4 ай бұрын
I have a doubt at 10:12 at line number 10. Why that mpp[a] = i is used there.... If any one knows please explain
@shreyamittal91524 ай бұрын
same doubt
@mannusharma32282 ай бұрын
To store that key value in map...
@rumiNITPatnaАй бұрын
amazing video striver!
@ITSuyashTiwari9 ай бұрын
i think for the last solution time complexity should be nlogn
@udaytewary3809 Жыл бұрын
Understood bhaiya 🙏 ❤️
@Raj10185 Жыл бұрын
Understood Everything Striver:)
@VarunSingh-mh9qy10 ай бұрын
didnt using unordered_map instead of map reduces the time complexity to O(N)?
@dikshasoni52a985 ай бұрын
What is the optimal solution for this ques variety 2 where we have to print the indices of the two numbers. He said hashing is not an optimal approach. Is there any other method possible?
@abhijeetmishra3804 Жыл бұрын
understood bhaiya. u r best
@vinayakd44447 ай бұрын
What to do if for the optimal solution there are duplicate elements? The next occurrence of the element overwrite the previous index and it leads to wrong answers if we were to return all the solutions. However the current code works if there are no duplicate elements and if only one unique solutions exists. Can someone tell me if they found a good approach to deal with duplicate elements (when we have to return index)