Two Sum - Pair with Given Sum | GFG POTD | 5 Minutes Code | GeeksForGeeks | DSA

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

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

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

    chromewebstore.google.com/detail/dsa-video-solutions/fplacgmeefidnohgepjcnabcaakfbknm
    Check out this cool extension with which you can unlock DSA video tutorial instantly on GeeksforGeeks with a single click. Its completely safe.
    Let me know if you have any suggestions.

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

    amazing explanation

    • @5minutescode
      @5minutescode  18 วันที่ผ่านมา

      Glad it helped :)

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

    Guyss please subscribe 🥰🥰🥰

  • @AdityaSingh-nu4jl
    @AdityaSingh-nu4jl 18 วันที่ผ่านมา

    sir what you explained is clear but i am confused why we are storing values in hst....even i am not able to build logic why 16-6=10 is present in hst😵‍💫

  • @AdityaSingh-nu4jl
    @AdityaSingh-nu4jl 18 วันที่ผ่านมา

    @AdityaSingh-nu4jl
    0 seconds ago
    sir i have created this code in pytho but dont know why it's failing at 309th case of gfg ...
    my approch is searching in set has complexity of O(1) that'swhy target-x should be there in set..
    my code is
    class Solution:
    def twoSum(self, arr, target):
    y = set(arr) # Convert the array to a set
    for x in arr:
    if (target - x) in y:
    return True
    return False

    • @5minutescode
      @5minutescode  18 วันที่ผ่านมา

      suppose array is [2,5] and target is 10. for x =5, I will check if target - 5 is present in set ? yes its present so your code will return true which is wrong. I hope you got it. :)