2 Sum Problem | 2 types of the same problem for Interviews | Brute-Better-Optimal

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025

ความคิดเห็น •

  • @takeUforward
    @takeUforward  ปีที่แล้ว +119

    Let's march ahead, and create an unmatchable DSA course! ❤
    Timestamps pleaseeee
    Use the problem links in the description.

    • @prithammahato1915
      @prithammahato1915 ปีที่แล้ว +2

      0.45 - BRUTE SOL
      5.13 - BETTER APPROACH (USING HASHING)
      11.55 - OPTIMAL APPROACH (USING 2 POINTER)

    • @prithammahato1915
      @prithammahato1915 ปีที่แล้ว

      0.45
      BRUTE
      5.13
      BETTER
      11.55
      OPTIMAL

    • @amitranjan6998
      @amitranjan6998 ปีที่แล้ว

      @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
      @RamanKumar-er8ie ปีที่แล้ว

      it does not work on tc=-3,-2,2,3,3 any please help me out in this

    • @abhinavennala9613
      @abhinavennala9613 ปีที่แล้ว

      @@RamanKumar-er8ie what is the target?

  • @TheITEngineer
    @TheITEngineer 4 หลายเดือนก่อน +125

    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 ❤

    • @Pai5566la
      @Pai5566la 4 หลายเดือนก่อน +4

      Bro, can you say about your complete interview experience

    • @dhruvbudhwani7599
      @dhruvbudhwani7599 3 หลายเดือนก่อน +4

      Don't lie 😅

    • @shifteditz06
      @shifteditz06 3 หลายเดือนก่อน +1

      where, which company, how much lpa?

    • @kushagrakulshrestha2966
      @kushagrakulshrestha2966 3 หลายเดือนก่อน +1

      dont play games with us man

  • @habeeblaimusa4466
    @habeeblaimusa4466 ปีที่แล้ว +265

    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
      @kushalchakraborty6970 ปีที่แล้ว

      Bro ,I need some tips to increase my 🍆?

    • @kulkarnisoham
      @kulkarnisoham ปีที่แล้ว +29

      That's a complement to whole country..!!

    • @Fe-ironman
      @Fe-ironman ปีที่แล้ว

      no@@kulkarnisoham

    • @barnam_das
      @barnam_das 11 หลายเดือนก่อน +5

      yes my boy, you can do it lets gooooo !!!!

    • @ArvindSingh-wj7vy
      @ArvindSingh-wj7vy 9 หลายเดือนก่อน +4

      Thank you from India on behalf of Striver 😂

  • @pragmaticcoder6910
    @pragmaticcoder6910 ปีที่แล้ว +30

    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.

  • @09ankurjaiswal85
    @09ankurjaiswal85 ปีที่แล้ว +53

    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-we9ce
      @KP-we9ce ปีที่แล้ว +1

      @takeUforward

    • @manideep7148
      @manideep7148 7 หลายเดือนก่อน

      ​ @takeUforward

  • @many987
    @many987 ปีที่แล้ว +15

    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
    @suravighosal9934 ปีที่แล้ว +18

    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.❤️

  • @aryansinha1818
    @aryansinha1818 ปีที่แล้ว +51

    Man you have changed a lot, this new version feels like a super saiyan mode.

  • @harshitrautela6585
    @harshitrautela6585 ปีที่แล้ว +1

    🎯 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

  • @Josuke217
    @Josuke217 6 หลายเดือนก่อน +8

    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.

    • @Josuke217
      @Josuke217 6 หลายเดือนก่อน

      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_Turtle
      @Squirt_Turtle 6 หลายเดือนก่อน +3

      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-b4m9p
      @KrishnaKumar-b4m9p 4 หลายเดือนก่อน

      @@Josuke217 same

  • @itzmartin20
    @itzmartin20 ปีที่แล้ว +6

    Understood! Thanks a billion for your top-notch explaination brother!

  • @harshavardhan184
    @harshavardhan184 ปีที่แล้ว +46

    This is the consistency we need from you bhai! 🔥

  • @secretcoder7
    @secretcoder7 ปีที่แล้ว +5

    GREAT BHAIYA I buy multiple dsa courses but i only understand with ur lectures
    🤗🤗

  • @md.ualiurrahmanrahat2400
    @md.ualiurrahmanrahat2400 ปีที่แล้ว +4

    Done this video. Amazing explanation. Learning amazing. Growing amazingly.

  • @parakhpatel93
    @parakhpatel93 ปีที่แล้ว +6

    this 5-star add is just crazy!!

  • @PrithaMajumder
    @PrithaMajumder 8 หลายเดือนก่อน +5

    Raj, Thanks a lot for This Amazing Video about C++ Arrays
    Video - 5 Completed ✅

  • @AbjSir
    @AbjSir ปีที่แล้ว +4

    2 pointer approach was very beautiful

  • @karamveeryadav8824
    @karamveeryadav8824 8 หลายเดือนก่อน +1

    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.

  • @parthkolgiri7501
    @parthkolgiri7501 ปีที่แล้ว +15

    When he introduced two pointer method my mind was like 🤯💥 Thank you striver!!!

  • @tanmaykarn
    @tanmaykarn ปีที่แล้ว +3

    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

  • @KomalSingh-qr4mu
    @KomalSingh-qr4mu 6 หลายเดือนก่อน +1

    Understood ! This is the first ques of my challenge 😃

  • @hareshnayak7302
    @hareshnayak7302 10 หลายเดือนก่อน +1

    Understood, Thank you strivers for this amazing video.

  • @BuragapuHaritha
    @BuragapuHaritha 6 หลายเดือนก่อน

    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....!!!

    • @PavitraYakkali
      @PavitraYakkali 4 หลายเดือนก่อน

      if you submit this two pointer approach in leet code is it accepted??

  • @sagnikbose5823
    @sagnikbose5823 ปีที่แล้ว +6

    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!

  • @anamikarawat3698
    @anamikarawat3698 ปีที่แล้ว +10

    Thankss bhaiya for this consistency ❤️🙌
    My placement is coming soon I'm in 6th semester!!🙂

    • @legendrose6828
      @legendrose6828 ปีที่แล้ว

      me too, can we connect on linkedin?

    • @jayrathod7957
      @jayrathod7957 ปีที่แล้ว

      Hello bhaiya how was it?
      I'm here at 3rd sem 🤔

    • @chiragdusad2015
      @chiragdusad2015 11 หลายเดือนก่อน

      Hey!
      Do you get the placements or how was your experience?

  • @sagestudy
    @sagestudy ปีที่แล้ว +3

    You are Great Sir! I love your explanation !!

  • @yashwanthostwal6947
    @yashwanthostwal6947 ปีที่แล้ว +1

    int main() {int n=3;
    int array[3]={3,2,4}; int target=6;
    for(int i=0; i

  • @Tabrez-cm4cq
    @Tabrez-cm4cq หลายเดือนก่อน

    Great content it takes a lot of effort to make such hard topics enjoyable ❤

  • @alwin3000z
    @alwin3000z 4 หลายเดือนก่อน

    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.

  • @harshukey6072
    @harshukey6072 ปีที่แล้ว +2

    Understood 🎉
    40 lakh

  • @JatinderDhiman-e4c
    @JatinderDhiman-e4c ปีที่แล้ว +1

    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 ?

  • @cinime
    @cinime ปีที่แล้ว

    Understood! Super awesome explanation as always, thank you very very much for your effort!!

  • @sunilkamat8199
    @sunilkamat8199 ปีที่แล้ว +2

    Brute -> Better > Optimal = BEST👌

  • @tamilmukbang3789
    @tamilmukbang3789 10 หลายเดือนก่อน +1

    understood. Thank youuuu

  • @HassanAbbas-wy7wj
    @HassanAbbas-wy7wj 5 หลายเดือนก่อน

    love you striver😍 you are the best teacher and mentor

  • @SigmaEditsbr
    @SigmaEditsbr 10 หลายเดือนก่อน

    Thanks sir for provide us this type of content ❤❤❤

  • @vansssssssssssss
    @vansssssssssssss 22 วันที่ผ่านมา

    understood ! very clear explanation!!

  • @vinothkannaramsingh8224
    @vinothkannaramsingh8224 10 วันที่ผ่านมา +1

    Variant 2 solution here:
    class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
    list = []
    for i in range(0, len(nums)):
    list.append([nums[i], i])
    list.sort()
    print(list)
    i = 0
    j = len(nums)-1
    while i < j:
    sum = list[i][0] + list[j][0]
    if sum == target:
    return(list[i][1], list[j][1])
    elif sum > target:
    j = j-1
    else:
    i = i+1

    • @JK-de2gh
      @JK-de2gh 7 วันที่ผ่านมา +1

      dont do it in python

    • @vinothkannaramsingh8224
      @vinothkannaramsingh8224 7 วันที่ผ่านมา

      @@JK-de2gh Why ??. Python is my ♥

    • @JK-de2gh
      @JK-de2gh 6 วันที่ผ่านมา +1

      @@vinothkannaramsingh8224 i now python more than java......but in interveiws they ask to code in java or c++.....python sucks in dsa....that's the truth....

    • @vinothkannaramsingh8224
      @vinothkannaramsingh8224 6 วันที่ผ่านมา

      @@JK-de2gh Language doesn't matter bro

    • @JK-de2gh
      @JK-de2gh 6 วันที่ผ่านมา +1

      @ yeah unless u use any other inbuilt libraries in python that iso not present in any other languages.....

  • @sreescorner
    @sreescorner ปีที่แล้ว +2

    Thanks a lot, very clear explanation

  • @rahulsbhatt
    @rahulsbhatt หลายเดือนก่อน

    Thank you so much for posting this!

  • @nihalshaikh196
    @nihalshaikh196 10 หลายเดือนก่อน +5

    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?

    • @arpit3242
      @arpit3242 8 หลายเดือนก่อน +4

      Two pointer approach is not that much optimal approach, but it is used when we want to find the answer without "map" data structure.

  • @harshalparanjiya5850
    @harshalparanjiya5850 หลายเดือนก่อน +3

    let's go 28 december 🔥🔥

  • @nagame859
    @nagame859 ปีที่แล้ว +1

    Top notch 🤩. Understood

  • @movocode
    @movocode 6 หลายเดือนก่อน +1

    10:36
    mpp.insert({nums[i], i}); is more optimised than
    mpp[num] = i; (used in video)

    • @lofiboy7866
      @lofiboy7866 3 หลายเดือนก่อน

      Explain why

  • @m_fi8926
    @m_fi8926 5 หลายเดือนก่อน +1

    in the brute force approach you should have initialized j=i+1;

  • @arunimachakraborty1175
    @arunimachakraborty1175 ปีที่แล้ว +1

    Awesome explanation, thanks a lot

  • @sayakghosh5104
    @sayakghosh5104 ปีที่แล้ว +1

    Understood!!!...Great as always. :)

  • @rhapsody4025
    @rhapsody4025 ปีที่แล้ว +1

    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
      @venkatesh_kens ปีที่แล้ว +1

      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
      @venkatesh_kens ปีที่แล้ว +1

      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
      @venkatesh_kens ปีที่แล้ว

      And you can see him saying it at 16:51

    • @balajik7376
      @balajik7376 10 หลายเดือนก่อน

      Got the same doubt

    • @balajik7376
      @balajik7376 10 หลายเดือนก่อน +1

      ​@@venkatesh_kensyou cleared it thanks❤

  • @charuwaka1
    @charuwaka1 11 หลายเดือนก่อน

    3:33 here you can keep j=i+1 instead of 0 so you don' need to write i==j

  • @bhavyasharma3500
    @bhavyasharma3500 ปีที่แล้ว +2

    Hats off to you striver bro

  • @Krishcode264
    @Krishcode264 3 วันที่ผ่านมา

    10:32 how about [3,3] and amount is 6 , when we have same keys present

  • @Nishantkumar-oh9th
    @Nishantkumar-oh9th ปีที่แล้ว +1

    HE just killed it as it says🤗

  • @zameeralucknowi872
    @zameeralucknowi872 ปีที่แล้ว +1

    Thank u soo much Dada, u r the real inspiration. Respect++;

  • @poojadasari8140
    @poojadasari8140 ปีที่แล้ว

    Understood. Very clear explanation

  • @shubhamlipane8634
    @shubhamlipane8634 ปีที่แล้ว +1

    Understood
    Thank You :-)

  • @shafiulhaque6583
    @shafiulhaque6583 ปีที่แล้ว +3

    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
      @aashishomre1624 ปีที่แล้ว +5

      Aftet sorting indices are changed

    • @himanshukaushik9223
      @himanshukaushik9223 ปีที่แล้ว

      ​@@aashishomre1624 bhai return hum curly braces ma kyu nahi kar sakta hai

    • @aashishomre1624
      @aashishomre1624 ปีที่แล้ว

      Bcoz return type function ka vector hai {-1,-1} indicating no pair found

    • @aashishomre1624
      @aashishomre1624 ปีที่แล้ว

      vector vect{ 10, 20, 30 }; this syntax is used

  • @kapilraivines8486
    @kapilraivines8486 9 หลายเดือนก่อน

    Hey Striver I am from Jupiter... I love your DSA playlist

  • @ronakparjapati2264
    @ronakparjapati2264 9 หลายเดือนก่อน +3

    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...

  • @himanshupathak6078
    @himanshupathak6078 29 วันที่ผ่านมา

    UNDERSTOOD!! ❤❤

  • @banothutharun2743
    @banothutharun2743 11 หลายเดือนก่อน +1

    understood sir

  • @lifehustlers164
    @lifehustlers164 ปีที่แล้ว +1

    Completed 5/28!!!

  • @DeepakKumar-xj4ul
    @DeepakKumar-xj4ul 10 หลายเดือนก่อน

    understood everything Thanks a lot sir!

  • @prashantindurkar1457
    @prashantindurkar1457 4 หลายเดือนก่อน

    Top notch . Understood

  • @rumiNITPatna
    @rumiNITPatna 3 หลายเดือนก่อน

    amazing video striver!

  • @user-zn3be9ik1x
    @user-zn3be9ik1x ปีที่แล้ว +2

    Pls make videos on sliding windows types questions and the types

  • @mohithvaishnav4317
    @mohithvaishnav4317 ปีที่แล้ว

    you jus make things easier..

  • @kingbadshah452
    @kingbadshah452 ปีที่แล้ว

    understood everything .... thanks striver

  • @samuelfrank1369
    @samuelfrank1369 ปีที่แล้ว

    Understood. Thanks a lot. Make More videos please......

  • @AnjuGupta-sz1uk
    @AnjuGupta-sz1uk ปีที่แล้ว

    understood bhaiya! really well explained..

  • @culeforever5408
    @culeforever5408 ปีที่แล้ว +1

    understood

  • @m.nirupreddy8001
    @m.nirupreddy8001 ปีที่แล้ว

    Understood! great explanation

  • @udaytewary3809
    @udaytewary3809 ปีที่แล้ว

    Understood bhaiya 🙏 ❤️

  • @parthchauhan4957
    @parthchauhan4957 หลายเดือนก่อน

    @takeuforward you said that in the variety 2 problem in the optimal solution we would end up taking O(2*N) space but I was thinking, can't we just return the left and right indices as integers when the sum is equal to the target?

  • @samlinus836
    @samlinus836 ปีที่แล้ว +1

    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
      @ayushmittal9666 ปีที่แล้ว +1

      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
      @samlinus836 ปีที่แล้ว

      @@ayushmittal9666 Understood thanks

  • @rishabkrishnakumar7446
    @rishabkrishnakumar7446 19 วันที่ผ่านมา

    what should we do if there is more than one pair of elements adding to 14.like 8,6 in index 1 and 3.and 10,4 in 2 and 4 index

  • @rithishkumargajjala341
    @rithishkumargajjala341 หลายเดือนก่อน +1

    how would you return the index of the of elements in the two-pointer case as the array is now sorted and the indices are changed?

  • @jay8118
    @jay8118 ปีที่แล้ว +2

    Job ke saath saath Padhana koi inse sikhe..🙌🙌

  • @abhijeetmishra3804
    @abhijeetmishra3804 ปีที่แล้ว

    understood bhaiya. u r best

  • @ShravanKumar-wg9pv
    @ShravanKumar-wg9pv 7 หลายเดือนก่อน +1

    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

  • @nice_random_guy5347
    @nice_random_guy5347 15 วันที่ผ่านมา

    Understood! Thanks

  • @anantadevraj8445
    @anantadevraj8445 ปีที่แล้ว

    understand fully...😄

  • @RahulUnscripted_
    @RahulUnscripted_ 8 หลายเดือนก่อน +1

    Can anyone pls explain why it is checked whether remaining is not equal to mp.end() 👀👀

  • @devil_m_0069
    @devil_m_0069 8 หลายเดือนก่อน

    while (left

  • @parasarora5869
    @parasarora5869 2 หลายเดือนก่อน

    Thank you. ❤

  • @HimanshuChamoli-j2v
    @HimanshuChamoli-j2v 4 หลายเดือนก่อน

    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

  • @_hulk748
    @_hulk748 ปีที่แล้ว

    understood sir❤🙇‍♂️🙏

  • @dhruvmishra3411
    @dhruvmishra3411 ปีที่แล้ว

    Best explanation

  • @saibunny1253
    @saibunny1253 6 หลายเดือนก่อน +1

    thank you anna

  • @saddatsabanature4307
    @saddatsabanature4307 10 หลายเดือนก่อน

    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)

  • @konankikeerthi
    @konankikeerthi 8 หลายเดือนก่อน

    Understood bro.. thank you

  • @simmi641
    @simmi641 11 หลายเดือนก่อน

    Thank you striver❤

  • @DK-ox7ze
    @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
      @lakshitamanie85 ปีที่แล้ว +1

      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.

  • @gersonlopes1471
    @gersonlopes1471 ปีที่แล้ว

    Great job. Thanks.

  • @torishi82
    @torishi82 6 หลายเดือนก่อน

    Samaj aa gaya!!

  • @DevashishJose
    @DevashishJose ปีที่แล้ว

    Understood. Thank you.

  • @niranjanv2001
    @niranjanv2001 7 วันที่ผ่านมา

    How does finding take O(n^2) in the worst case for unordered_map? Isn't it O(n) due to collisions?

  • @AbhishekSingh-cg3fx
    @AbhishekSingh-cg3fx 2 หลายเดือนก่อน

    video mai jo code likha hai usme map initialize kese ho rha hai 10:36 p?

  • @AhanaVats-m7h
    @AhanaVats-m7h 9 หลายเดือนก่อน

    understood brother💞

  • @Manipinnaka
    @Manipinnaka 6 หลายเดือนก่อน

    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

  • @arshpuri3079
    @arshpuri3079 5 หลายเดือนก่อน +1

    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

    • @reshmah1497
      @reshmah1497 4 หลายเดือนก่อน

      Only after filling the map as we iterate on the array, we can find elements.