4 Sum | Brute - Better - Optimal with Codes

Поделиться
HTML-код
  • Опубликовано: 22 янв 2025

Комментарии • 334

  • @takeUforward
    @takeUforward  Год назад +18

    Please watch our new video on the same topic: ruclips.net/video/eD95WRfh81c/видео.html

    • @uniqueyuvrajgaming3392
      @uniqueyuvrajgaming3392 Год назад

      You said it is O(n3) but sorting will take some time to what about that?

    • @janardhan2jordan
      @janardhan2jordan 11 месяцев назад

      ​@@uniqueyuvrajgaming3392nlog n is basically negligible in comparision of n3 thats why is it not included

    • @TaimoorKhan-h6l
      @TaimoorKhan-h6l 7 месяцев назад

      Sir,I have one confusion about the time complexity.
      Inside the innermost loop we have the insert operation in set which take O(logN) in the worst case considering we have n elements inside the side.
      If we are taking the worst case means that the if(sum==target) is true for each condition.Then Why we are not considering it's complexity.
      According to my calculation,Time Complexity is O(N^3(logN)).
      Please sir reply.
      Thank you in Advance.

    • @TaimoorKhan-h6l
      @TaimoorKhan-h6l 7 месяцев назад +1

      @@uniqueyuvrajgaming3392 Sorting will have always 4 elements which will take constant time.

    • @mohitshahu4601
      @mohitshahu4601 4 месяца назад

      ​@@TaimoorKhan-h6l do you want to use ordered set?

  • @shailesh_rajpurohit
    @shailesh_rajpurohit Год назад +264

    Note: 0:42 Make sure you watch the 3Sum before doing the 4Sum .
    🙂

  • @Akash-yr2if
    @Akash-yr2if Год назад +83

    0:44 Striver's Smile Says it all

    • @brijmohan_f_s
      @brijmohan_f_s Год назад +5

      you got my point bro😁

    • @AkOp-bf9vm
      @AkOp-bf9vm 7 месяцев назад +1

      bhai bhai🫡🫡😂. what a detailing bro

    • @guneeshvats46
      @guneeshvats46 3 месяца назад

      Damn I was about to comment this

    • @SIVAKUMAR-bj2vl
      @SIVAKUMAR-bj2vl 3 месяца назад

      Hhahahahahahaha

  • @takeUforward
    @takeUforward  Год назад +78

    Do give us a like and subscribe, it won't cost you anything, but it will highly motivate us to create more such type of videos :)

    • @rishav144
      @rishav144 Год назад +4

      striver ..king of DSA

    • @shra1
      @shra1 Год назад

      The if condition inside while to check if(k

    • @codemania2878
      @codemania2878 Год назад

      sir which whiteboard pen app you use for explain the code

    • @itsmrcrazy7670
      @itsmrcrazy7670 Год назад

      hey striver you forgot to add time complexity required for --sorting array --optimal approach so it will be O(NlogN) + O(N^2). plz update

    • @BhaveshKumar-z1h
      @BhaveshKumar-z1h Год назад

      @@codemania2878 He is using an iPad and its default Notes app​

  • @ashishashish1403
    @ashishashish1403 7 месяцев назад +40

    Whole video is about 4 sum but 0:40 to 0:50 is wholesome

  • @jatinsareen7771
    @jatinsareen7771 Год назад +91

    3 sum was awesome, 4 sum was fantastic!!!!

  • @mehulthuletiya497
    @mehulthuletiya497 Год назад +44

    00:54 Problem Statement
    02:24 Brute force approach
    03:08 Code
    05:38 Complexity
    06:14 Better approach
    11:31 Code
    13:22 Complexity
    14:54 Optimal approach
    21:59 Code
    27:04 Complexity

    • @takeUforward
      @takeUforward  Год назад +57

      You watch all the videos? I see you daily updating me with timestamps, massive thanks for that.

    • @mehulthuletiya497
      @mehulthuletiya497 Год назад +29

      ​​@@takeUforward Yes, I watch the all the videos. After the watching video i comment the Timestamp.
      Recursion and Backtracking series is the one of the best explanation and understanding with your teaching style. I completed 2 days ago.

    • @salihedneer8975
      @salihedneer8975 Год назад +1

      @@takeUforward striver please update timestamp in disucssion so that ppl can access it easily

  • @yashsharma6396
    @yashsharma6396 Год назад +238

    Excited to do 4sum after completing 3sum yesterday

    • @gareer2436
      @gareer2436 Год назад +58

      Damn bro include me next time

    • @yashsharma6396
      @yashsharma6396 Год назад +47

      ​@@gareer2436 you know how to bend?😂😂

    • @gregorirasputin659
      @gregorirasputin659 Год назад +25

      Yaar tum log bohat tharki ho 😂

    • @gareer2436
      @gareer2436 Год назад

      @@yashsharma6396 no but I know what to do when someone bends...😏
      Lay them down and..
      Massage their backs of course!

    • @gareer2436
      @gareer2436 Год назад +18

      @@gregorirasputin659 ma to sath me problem solve krne ki baat kr raha tha bro... tum kya soch liye?😏

  • @arujgarg7267
    @arujgarg7267 Год назад +64

    Finally did 4 sum, amazing experience

    • @gareer2436
      @gareer2436 Год назад +11

      Can you elaborate your experience? Asking for a friend

    • @catalyst8654
      @catalyst8654 Год назад +1

      can you explain about your experience...🙂🙂

    • @leisuretime4198
      @leisuretime4198 Год назад

      @@catalyst8654 🤣🤣

    • @Akash-yr2if
      @Akash-yr2if Год назад +1

      Would you take a moment to share your experience with us.

    • @subratkumarnayak2560
      @subratkumarnayak2560 Месяц назад

      The problem right? RIGHT??

  • @cinvest2411
    @cinvest2411 Год назад +12

    You should not take I upto

  • @selvaarumugam370
    @selvaarumugam370 Год назад +10

    the way you explain the two pointer approaches and the use of them makes two pointer approach the easiest way to solve a problem. I fell in love the way you are teaching these concepts.

  • @dishankbaid
    @dishankbaid Год назад +36

    The consistency level of striver is really the source of motivation 🔥.

  • @shubhamagarwal1434
    @shubhamagarwal1434 5 месяцев назад +3

    #Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.

  • @impalash_ag
    @impalash_ag 6 месяцев назад +12

    Hi Raj, there are 2 slight mistakes in your optimal solution.
    1: The 1st for loop will run till n-3 and 2nd for loop will run till n-2 instead of n, because we need to allocate last 2 elements to our two pointers and as per your code when i=n-2, j becomes n-1 (j=i+1=n-2+1) and num[k] throws out of bound exception, because k becomes n(k=j+1)
    2: We could also increment low and decrement high when sumtarget respectively until there are duplicates for code to be more optimised.
    3: Here's the more readable code(JAVA):
    class Solution {
    public List fourSum(int[] nums, int target) {
    int n = nums.length;
    List result = new ArrayList();
    Arrays.sort(nums);
    for(int i=0; i

    • @_Arunvfx
      @_Arunvfx 6 месяцев назад +5

      hatsoff bro i was confused for 4 hours for optimal solution that passes all test cases.after seeing your comment it helped me to understand it.thankyou :)

    • @impalash_ag
      @impalash_ag 6 месяцев назад +5

      @@_Arunvfx glad you finally understood it. Keep pushing forward 😃

    • @rockpaperscissors1781
      @rockpaperscissors1781 2 месяца назад

      Afaik, it won't throw out of bound exception, because there is a check being done (k < l). In ur case, k takes n and l takes n - 1.

  • @shubhrajyotipoddar1684
    @shubhrajyotipoddar1684 Год назад +21

    bro couldn't control his laugh during 3sum , 4sum intro and had to cut the clip 🤣

  • @shubha_jagadeesh
    @shubha_jagadeesh 3 месяца назад +1

    fell in love with your way of explanation❤

  • @omkarsawant9267
    @omkarsawant9267 Год назад +2

    Time Complexity: O(n log n)
    Space Complexity: O(n)
    #include
    #include
    #include
    using namespace std;
    vector fourSum(vector &nums, int target)
    {
    // sort the array
    sort(nums.begin(), nums.end());
    // initialize result vector
    vector result;
    int n = nums.size();
    // iterate through array with two pointers
    for (int i = 0; i < n; i++)
    {
    // skip duplicate elements
    if (i > 0 && nums[i] == nums[i - 1])
    {
    continue;
    }
    for (int j = i + 1; j < n - 2; j++)
    {
    // skip duplicate elements
    if (j > i + 1 && nums[j] == nums[j - 1])
    {
    continue;
    }
    // use two pointers for remaining elements
    int left = j + 1;
    int right = n - 1;
    while (left < right)
    {
    int currentSum = nums[i] + nums[j] + nums[left] + nums[right];
    if (currentSum == target)
    {
    result.push_back({nums[i], nums[j], nums[left], nums[right]});

    // skip duplicate elements
    while (left < right && nums[left] == nums[left + 1])
    {
    left++;
    }
    while (left < right && nums[right] == nums[right - 1])
    {
    right--;
    }
    // Move pointers
    left++;
    right--;
    }
    else if (currentSum < target)
    {
    // If the sum is less than the target, move the left pointer to the right
    left++;
    }
    else
    {
    // If the sum is greater than the target, move the right pointer to the left
    right--;
    }
    }
    }
    }
    return result;
    }
    int main()
    {
    // Example usage
    vector nums = {1, 0, -1, 0, -2, 2};
    int target = 0;
    // Call the fourSum function
    vector result = fourSum(nums, target);
    // Print the unique quadruplets
    for (const auto &quadruplet : result)
    {
    cout

    • @akashchoudhary6876
      @akashchoudhary6876 6 месяцев назад +1

      kuch bhi, same solution hai upar wala time complexity n3 hai, apki nlogn kaise aa gayi

    • @omkarsawant9267
      @omkarsawant9267 6 месяцев назад

      @@akashchoudhary6876 the overall time complexity of the fourSum function is O(nlog⁡n+n^3)which simplifies to O(n^3)in Big O notation, assuming the input is sufficiently large.

    • @omkarsawant9267
      @omkarsawant9267 6 месяцев назад

      @@akashchoudhary6876 sorting in cpp will take O(nlogn)

    • @THEReFleX
      @THEReFleX 2 месяца назад

      @@akashchoudhary6876 hahahahah

  • @hareshnayak7302
    @hareshnayak7302 10 месяцев назад +1

    Understood,Thanks striver for this amazing video.

  • @praveennemagoudar3442
    @praveennemagoudar3442 9 месяцев назад +1

    wow,....wow....wah..awesome expaination. undestood bro..hatsoff to you.

  • @MdKaif-bf3nz
    @MdKaif-bf3nz 7 месяцев назад

    Thank you so much Striver brother, you taught the 3sum and 4sum very clearly. 💀💀
    ok jokes apart lol, this series is just too good, i can literally find every concept DSA related a lot of questions of each and every concept.

  • @rahulbhola9026
    @rahulbhola9026 29 дней назад

    Thanks for clearing my concepts

  • @ankitadas5833
    @ankitadas5833 Год назад +2

    Though I am little bit late, in this A to Z DSA Playlist But I covered All previous Videos within a week & now just completed 4 Sum. Striver Sir You are great! You will going to create a history in DSA course very soon around all over the World … I don't have the proper words to express my gratitude to you. All the Best Sir God bless you .

    • @ankitadas5833
      @ankitadas5833 Год назад

      @@ArjunS-hi3vl Yes

    • @DR-mq1le
      @DR-mq1le Год назад

      have you completed the course ? im also quite late in starting the course and moving at about the same pace as you

    • @ankitsharda1131
      @ankitsharda1131 Год назад

      @ankitadas5833 hey I would like to know if you have completed entire striver a2z dsa course? If yes, how much time did you take to complete entire course?

  • @Mythri333
    @Mythri333 2 месяца назад

    Ahaaa... excellent explanation 😊

  • @bkmeher9005
    @bkmeher9005 8 месяцев назад

    uffffffff.... understood , bahut bhala se bujhi hela bhai

  • @asgarh4589
    @asgarh4589 Год назад

    People who are aware of 2 pointer approach, watch from 14:56, saves a lot of time.

  • @gauravsoni5424
    @gauravsoni5424 Год назад

    best explanation on you tube

  • @kaichang8186
    @kaichang8186 3 месяца назад

    understood, thanks for the perfect explanation

  • @kanyapandey
    @kanyapandey Год назад

    Thanks a ton for explaining in simplest way 🙏🙏🙏🙏🙏🙏

  • @helloworld2054
    @helloworld2054 Год назад +19

    This has to be the horniest coding problem 🌚

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 10 месяцев назад

    Awesome Lecture Sir............

  • @adebisisheriff159
    @adebisisheriff159 Год назад

    Striver..... you are amazing.................................... Thanks so much bro

  • @AbhimanyuKumar-pw3je
    @AbhimanyuKumar-pw3je Год назад +5

    if u are stuck at test case 281 in leet code then :-
    class Solution {
    public:
    vector fourSum(vector& nums, int target) {
    int n =nums.size();
    vector ans;
    sort(nums.begin(),nums.end());
    for(auto it:nums)
    cout

  • @AbhishekKumar-cv1dh
    @AbhishekKumar-cv1dh Год назад

    Understood beautifully!! 🔥❤

  • @footballcreativeeverywhere260
    @footballcreativeeverywhere260 Год назад +1

    Great bhaiya ❤️🇮🇳 , ready for next one

  • @ra-onegaming1383
    @ra-onegaming1383 Год назад

    I have done this question using subsequence technique thanks u raj sir 😊 u teach really simple

  • @iamaniket9
    @iamaniket9 11 месяцев назад

    understood,thnx for the amazing video ❤❤❤❤👌👌💕💕

  • @nquanta1548
    @nquanta1548 Год назад

    Thankyou for the wonderful series ❤️🔥

  • @joeljacob4685
    @joeljacob4685 Год назад

    Understood!! Thanks for the nice explanation

  • @hydrocy.9165
    @hydrocy.9165 9 месяцев назад

    23:16 shouldnt j= i+1 will be second element? I cant understand

  • @narendrakumargupta9092
    @narendrakumargupta9092 Месяц назад

    bro couldnt help but smile 0:42

  • @THUNDER-kw3wq
    @THUNDER-kw3wq 6 месяцев назад +1

    Striverr bhai ke liye toh 10some bhi asaan hai...Jokes apart hes the best teacher on youtube

  • @SaiPhaniRam
    @SaiPhaniRam Месяц назад

    We can excluded the inner while loop for either "k" or "l" index. Incrementing "k" or decrementing "l" would suffice. As one takes care of the other.
    Updated Solution:
    ''
    Optimal Approach - Sorting and 2 Pointers
    TC = O(nlogn) + O(n^3)
    = O(nlogn) for sorting +
    O(n^2) for '2' outer loops * O(n) for inner while loop in their lifetime
    SC = O(number of quadruplets) for result array
    Dry Run:
    nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5], target = 8
    Possible combinations:
    [[1,1,1,5],[1,1,2,4],[1,1,3,3],[1,2,2,3]]
    '''
    n = len(nums)
    nums.sort()
    result = []
    for i in range(0, n):
    # Ignore duplicate combination
    if i > 0 and nums[i] == nums[i-1]:
    continue
    for j in range(i+1, n):
    # Ignore duplicate combination
    if j > i+1 and nums[j] == nums[j-1]:
    continue
    l, r = j+1, n-1
    while l < r:
    total = nums[i] + nums[j] + nums[l] + nums[r]
    if total > target:
    r -= 1
    elif total < target:
    l += 1
    else:
    # Quadruplet found
    store = [nums[i], nums[j], nums[l], nums[r]]
    result.append(store)
    # Avoid duplicates - Either increment 'l' or decrement 'r'
    # One takes care of the other
    l += 1
    while l < r and nums[l] == nums[l-1]:
    l += 1
    return result

  • @Ganesh-y5e9d
    @Ganesh-y5e9d 16 дней назад

    at 6 : 10 : i think for computing space complexity, we only compute space required by the algorithm. we don't add space taken by the result

  • @shivanichaudhary1427
    @shivanichaudhary1427 10 месяцев назад

    Amazing, thankyou!

  • @akankshajain3997
    @akankshajain3997 6 месяцев назад

    helpful to understand integer overflow

  • @shuvbhowmickbestin
    @shuvbhowmickbestin Месяц назад

    Code is not running for this test case:
    nums =
    [-1, -1, -1]
    target = -2
    if you're writing in a language like C# or Java where lists are considered reference types and the equality are based on references rather than actual values. The workaround in C# is to sort the list like usual and then use a *ValueTuple* to extract the values from the list and then adding this to the set as ValueTuples equality checks are value-based rather than reference which means two different valuetuples with the same numbers in the same order will still be considered as *EQUAL* whereas the same in a list would be considered as *UNEQUAL* due to a difference in references.

  • @Manishgupta200
    @Manishgupta200 Год назад +7

    It's amazing from brute to better to optimal similarly like 2Sum, 3Sum .. and my doubts in what's about 5-Sum, 6-Sum.. is any universal solution exist?

    • @harshshukla7675
      @harshshukla7675 Год назад

      Yes, the complexity will keep on increasing tho

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp Год назад +7

    After doing 4 Sum.... I think Sky is the limit 🌝

  • @Algorithmswithsubham
    @Algorithmswithsubham Год назад +4

    Sir app apne resume k project me konsa tech stack use kya haii. ❤ love your videos

  • @cinime
    @cinime Год назад +1

    Understood! Super wonderful explanation as always, thank you so so much for your effort!!

  • @gregorirasputin659
    @gregorirasputin659 Год назад +6

    Nice explanation. But the title is a bit too sus don't you think?

  • @ShivamSingh-g2x6l
    @ShivamSingh-g2x6l 11 месяцев назад +1

    in the brute force approach when we first added nums[i]+nums[k]+nums[k]+nums[l] and then checked if its == target then it gives integer overflow error regardless of sum being stored in long long variable but if we do it one by one like sum = nums[i]+nums[j] and then sum+=nums[k] and sum+=nums[l] then the error is resolved can anyone please explain to me how its working.

    • @EC20022ELAKKIYAC
      @EC20022ELAKKIYAC 11 месяцев назад

      did you found how does it works ? same doubt here

  • @konankikeerthi
    @konankikeerthi 7 месяцев назад

    Thank you bro. Understood

  • @saurabhtamta7295
    @saurabhtamta7295 10 месяцев назад +2

    why is it when i use:-
    long long sum = nums[i]+nums[j]+nums[k]+nums[l]
    -----it says runtime error but when i use :-
    long long sum = nums[i];
    sum+=nums[j];
    sum+=nums[k];
    sum+=nums[l];
    ----it works fine. Why is that?

  • @deadlockgaming8553
    @deadlockgaming8553 7 месяцев назад

    24:23 why not sum = nums[i] + nums[j] + nums[k] + nums[l] ?
    can anyone explain plz

    • @madhu_mohanreddy
      @madhu_mohanreddy 7 месяцев назад

      you can but you may may get an error!!

  • @satheeshbhukya9970
    @satheeshbhukya9970 Год назад

    excellent question....

  • @harshilpatel3205
    @harshilpatel3205 5 месяцев назад

    Understood 🙏🏻

  • @the_avii_7
    @the_avii_7 3 месяца назад

    Understood !!!!!

  • @astroblud
    @astroblud 5 месяцев назад

    Why aren't we considering the TC for inserting the vector in the set in brute and better approach ? Please lmk what I'm missing

    • @JK-de2gh
      @JK-de2gh 5 месяцев назад +1

      becoz for inserting and getting the element in set is o(1) just ignoring that....

    • @hemlockguys
      @hemlockguys 4 месяца назад

      its particularly constant because we are only storing quad's generated

  • @raghavkansal3765
    @raghavkansal3765 Год назад

    you are the best 🧿🧿

  • @aysams2
    @aysams2 Год назад

    04:20 - what does exceeding the integer limit mean? (when we are storing it in a long long)

    • @takeUforward
      @takeUforward  Год назад +1

      if you store in int it might exceed

    • @SANDEEPKUMAR-in6li
      @SANDEEPKUMAR-in6li Год назад

      @@takeUforward but in 3 sum we sum up like sum = nums[i]+nums[j]+nums[k] but in this 4 sum you sum up all the indices separately which is correct but I am getting error in a test case when I am doing sum = nums[i]+ nums[j]+ nums[k]+ nums[l]; why?

    • @Monika-vs6bw
      @Monika-vs6bw Год назад

      @@SANDEEPKUMAR-in6li the compiler has an algorithm for adding these numbers . while adding four numbers(big numbers) the algorithm needs a lot of space , but while adding two or three the space is under limit. hence adding them one by one is recomended.

  • @vagabondfoodie5788
    @vagabondfoodie5788 Год назад +2

    Aaj maza aa gya 3 sum karke🌚🌚🌚 ab 4 sum krunga

  • @tanishagarwal5992
    @tanishagarwal5992 Год назад

    When striver submits on Code Studio , it also showed him time complexity as O(n4 log n) but it doesn't show in mine. Why?

  • @tejaspatel2212
    @tejaspatel2212 Год назад +11

    Imagine someone getting your video, on Searching 3sum video or 4sum video on google 🌚😂

  • @himanshukaushik9223
    @himanshukaushik9223 Год назад +1

    Bhaiya is everything fine any health issues video is not coming ??

  • @bikramprajapati5358
    @bikramprajapati5358 Год назад

    Amazing Explanation

  • @D3vansh
    @D3vansh Год назад +14

    I think first i should learn 3SUM then will do 4SUM as you said

    • @takeUforward
      @takeUforward  Год назад +49

      Please learn 2 sum, then 3 sum, then only 4 sum should be implemented ! Yes in terms of problem.

    • @noobCoderStupid
      @noobCoderStupid Год назад +10

      @@takeUforward 😂😂

    • @shis10
      @shis10 Год назад +5

      @@takeUforward 🤣🤣🤣

    • @godson200
      @godson200 Год назад +10

      @@takeUforward sir but partner is not available how to do 2sum

    • @mohsin7343
      @mohsin7343 Год назад +17

      I am still with 1sum

  • @AkshayYadaveeb
    @AkshayYadaveeb 10 месяцев назад

    while i'm taking sum==target case in else it is not working like we did in three sum and if i put if(sum==target) at initial position it is working . why it is so ?

  • @UECAshutoshKumar
    @UECAshutoshKumar 7 месяцев назад

    Thank you!

  • @senseiAree
    @senseiAree Год назад

    Understood ❤

  • @203-aasritha2
    @203-aasritha2 11 месяцев назад

    We should consider the time complexity for sorting the given array right ?

  • @PrinceTripathi-j7u
    @PrinceTripathi-j7u Год назад

    Nice to do 4 sum.

  • @mainakdasgupta7130
    @mainakdasgupta7130 29 дней назад

    thank you sir

  • @myaccount09011975
    @myaccount09011975 6 месяцев назад

    What about Time complexity for sorting the arrray? I know it will be lesser than N3 in this case. But still good to mention that!. Thanks for putting all the hard word!.

  • @per.seus._
    @per.seus._ Год назад +1

    understood ❤

  • @ocean_vibes_asmr
    @ocean_vibes_asmr 2 месяца назад

    28.10 are we not using the space for vector temp = { , , , }; line no. 18 ??

    • @ictfan-ly8gh
      @ictfan-ly8gh 2 месяца назад +1

      That's bcoz bro there will always be 4 elements that are to be inserted in temp.
      So the s.c will be O(4)
      Which will not depend on N i.e. no of elements in vector.
      And as in S.C we ignore constants.so ignore it

    • @ocean_vibes_asmr
      @ocean_vibes_asmr 2 месяца назад

      @@ictfan-ly8gh got the point, thanks.

  • @VivekKumar-kx2zf
    @VivekKumar-kx2zf 9 месяцев назад

    why we are putting condition while(k

    • @brp3522
      @brp3522 6 месяцев назад

      If k crosses l then we have gone through all the possibilities. Imagine this if they crosses each other they will act like each other. After crossing K will give the elements L has already given and the same goes for L

  • @hiteshpanchal5772
    @hiteshpanchal5772 Год назад

    Thxu striver bhai 😊😊

  • @satyamsrivastava3423
    @satyamsrivastava3423 9 месяцев назад

    Just wanted to add the Time Complexity will also contain log(n) since we are sorting the array, right?

  • @DR-mq1le
    @DR-mq1le Год назад

    understood , thank you!

  • @lakshmiprasanna7058
    @lakshmiprasanna7058 Год назад

    Understood 💯💯💯

  • @ArunsinghParihar-j3j
    @ArunsinghParihar-j3j 11 месяцев назад

    Understood🤙

  • @RituSingh-ne1mk
    @RituSingh-ne1mk Год назад

    Understood!

  • @gugulothsrilakshmi8729
    @gugulothsrilakshmi8729 Год назад

    Why removing duplicates I'm not getting the concept in 3 sum problem too in optimal solution

  • @daminkhan5105
    @daminkhan5105 8 месяцев назад

    In the better approach why the code didn't gave runtime error for j and k when i = n - 1, because j = i + 1 and k = j + 1, making j and k going out of bounds of array so it should've thrown the error right?

    • @statuscreation9493
      @statuscreation9493 6 месяцев назад

      while starting for loop we also stated j and k should be less than n if it goes out of bound whole loop will end.. so no chance

    • @daminkhan5105
      @daminkhan5105 6 месяцев назад

      @@statuscreation9493 ohh got it thankyou bro

  • @RohitKumar-dy2gc
    @RohitKumar-dy2gc 9 месяцев назад

    easy peasy✨✨

  • @rishabgupta2733
    @rishabgupta2733 Год назад

    The complexity of better solution is n^4 *logn according to codestudio

  • @Shivi32590
    @Shivi32590 6 месяцев назад

    thank you

  • @himaniupadhyay8201
    @himaniupadhyay8201 Год назад +1

    Thanks Lord

  • @her_soulmate
    @her_soulmate Год назад

    Understood 🎉

  • @gautamsaxena4647
    @gautamsaxena4647 4 месяца назад

    understood bhaiya

  • @ayanakash9900
    @ayanakash9900 Год назад +2

    For optimal solution time complexity, we have to add sort() time too ig

  • @ravitejachandana6199
    @ravitejachandana6199 7 месяцев назад

    understood !

  • @rishabpurba3268
    @rishabpurba3268 4 месяца назад +1

    hey, does someone relate with this, i have trouble coming around the solution that i haven't come up with, i overthink and find it hard believing the solution?

  • @sanayaagarwal1907
    @sanayaagarwal1907 11 месяцев назад

    understood👍

  • @mdazizul-y7b
    @mdazizul-y7b 5 месяцев назад

    understood sir

  • @VishalPanwar-df5ek
    @VishalPanwar-df5ek Год назад

    Understood Srtiver!

  • @rajatpatra2593
    @rajatpatra2593 Год назад

    Understood ❤️

  • @hemantpatel1413
    @hemantpatel1413 7 месяцев назад

    Understood.

  • @srikarvinjamara2003
    @srikarvinjamara2003 Год назад

    Hi, thanks for the video explanation. I had one doubt. When we get the sum==target, we move the k and l pointers front and back respectively [not just once but until we get a different value for k and l pointers so as to not repeat the same ans]. Why are we not doing the same when {sumtarget}. [i.e. in these 2 cases we just do k+=1 or l-=1; shouldn't we here also move the k and l pointers ahead until we get a different value for them.] Please let me know if possible. Thanks!

    • @203-aasritha2
      @203-aasritha2 11 месяцев назад +1

      It goes the same as well. If we move the pointer and again we get the same set , the sum will be the same right ? therefor if the sum is less than zero , it remains the same and vice versa. Then the iteration completes and we will hit the same condition. This goes until we get another pair.