Triplet Sum in Array | GFG | Geeks for Geeks | Problem Solving | Hindi | FAANG | Shashwat

Sdílet
Vložit
  • čas přidán 4. 07. 2021
  • Java Plus DSA Complete Placement Course:
    • Java and DSA Course Pl...
    Problem Statement:
    Given an array arr of size n and an integer X. Find if there's a triplet in the array which sums up to the given integer X.
    Problem Link:
    practice.geeksforgeeks.org/pr...
    Company Tags:
    Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe
    Instagram Handle: (@shashwat_tiwari_st)
    shashwattiwari.page.link/shas...
    #ShashwatTiwari #coding​​ #problemsolving​ #leetcode​ #hackerrank​ #hackerearth​ #codechef​ #codesignal​ #algorithms​ #javaprogramming​ #sde​ #placement #programming

Komentáře • 25

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Před rokem

    This is a very old video, for better sound and camera quality DSA videos, learn from the below playlist!
    Java Plus DSA ( Java + DSA + Problem Solving )
    czcams.com/play/PLQ7ZAf76c0ZPVdhV1bAjFv0bQc1xHURzE.html

  • @sourishlahiri2894
    @sourishlahiri2894 Před 2 lety +3

    One of the most underrated channels on youtube , love your videos .

  • @priya2065
    @priya2065 Před rokem

    sir your explaination style is so good

  • @swagatochakraborty6043

    I thought of the hashset approach initially but it uses n space so I think sorting is a better approach - Also in GFG its said to solve in const. space

  • @AdityaGupta-zd5sq
    @AdityaGupta-zd5sq Před rokem

    love from upes college bhaiya

  • @maheshkeshwala2280
    @maheshkeshwala2280 Před 3 lety +1

    Nicely explained

  • @himanshunagar1510
    @himanshunagar1510 Před 2 lety +1

    Nice Explanation

  • @thehitmanhero3314
    @thehitmanhero3314 Před 3 lety

    Nicely explained 👍

  • @priyamtiwari391
    @priyamtiwari391 Před 2 lety +1

    hello shashwat bhaiya me too from upes dehradun

  • @abhishekchakrabarty2930
    @abhishekchakrabarty2930 Před 2 lety +2

    if the values are repeated then? for example 1,1,5,5,7,7,7,8 and we need number of pairs having 12 sum

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 2 lety

      But the example you gave, there are no Triplets that will sum up to 12.
      But to answer your question, repetition won't be a problem.
      Question: 5,5,5,7 and sum is 15.
      Try this question using map method which I told. You will get your answer

    • @abhishekchakrabarty2930
      @abhishekchakrabarty2930 Před 2 lety

      @@shashwat_tiwari_st yes sorry I forgot to mention ...only 2number pair

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 2 lety

      @@abhishekchakrabarty2930
      This is a different question check here: czcams.com/video/0VHC1KVHH0U/video.html

  • @AdityaPratapSingh-ss8wg
    @AdityaPratapSingh-ss8wg Před 2 lety +1

    Hey bro if we have question where we need to find number of triplet in the array with given sum then we can't do using hashing right ?

  • @rpatil1169
    @rpatil1169 Před 2 lety

    but exits method will do iteration under hood,

  • @gtx1650max-q
    @gtx1650max-q Před 2 lety +1

    Hey, why did you declare the hasmap inside the first loop and not outside.

    • @rocked789
      @rocked789 Před 2 lety

      same doubt

    • @gtx1650max-q
      @gtx1650max-q Před 2 lety

      @@rocked789 I dry ran it and understood why he did that

    • @rocked789
      @rocked789 Před 2 lety

      @@gtx1650max-q can u please explain?

    • @gtx1650max-q
      @gtx1650max-q Před 2 lety

      @@rocked789 it's tough to explain on comments. You should try dry run his code yourself I am sure you will get it

  • @aditiarora7456
    @aditiarora7456 Před rokem

    In HashMap solution,why the first for loop is running till n-2 ?

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před rokem +2

      Index n-2 is exclusive. ( < sign is used )
      Index 0 to Index n-3 will be the possible values for the first element, why it is so Because if we choose 2nd last or last element as the first candidate, we will not have enough elements left to make a triplet.
      So, if array is
      2, 3, 4, 6, 8.
      First elements can be 2, 3, 4 only.
      If we choose 6 as first element.
      Then 8 Will be the second element,
      But no element is left now so we will not be able to choose 3rd element, hence triplet will be incomplete.

    • @aditiarora7456
      @aditiarora7456 Před rokem

      @@shashwat_tiwari_st Thank you so much ♥♥