3 Sum Closest || Leetcode Daily Challenge || Code + Intuition + Example

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024
  • 16. 3Sum Closest
    Medium
    Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
    Example 1:
    Input: nums = [-1,2,1,-4], target = 1
    Output: 2
    Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
    Link to challenge : leetcode.com/p...

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

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

    the catch that at the second condition we only have to assign sum = arr[i]+arr[j]+arr[k], without doing any k-- or j++ had me going.
    Thank you so much :)

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

    Hey! how many problems have you solved on leetcode so far?

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

    You made this problem so easy to understand. Thanxxx!!

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

    Thankyou mam very nice and beautiful explanation can you please make video how to approch leetcode as begginer

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

    U explain so nicely and concrete i jst love ur video please make more such video

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

    //Same Explanation with different Solution
    Arrays.sort(nums);
    int n=nums.length;
    int closeSum = nums[0]+ nums[1]+nums[n-1];

    for(int i=0;i

  • @yogeshyts
    @yogeshyts 2 ปีที่แล้ว

    why we are not skipping duplicate and calculating everytime for duplicate,we can use
    // while (second < third and ar[second] == ar[second + 1]){
    // second++;
    // }
    but this is not working Don't know why
    please reply

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

    We can use three pointers right for optimum solution

  • @Mohit-te2jl
    @Mohit-te2jl 2 ปีที่แล้ว +1

    Nice and simpler explanation!

  • @webtechnology6439
    @webtechnology6439 2 ปีที่แล้ว

    plg view full code after submitting and code typing time view max screen or possible to press f11 to full window.

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

    Great Explanation

  • @jigarjoshi9198
    @jigarjoshi9198 2 ปีที่แล้ว

    what if i store the elements one by one in new array of size three and by sorting them i can find the sum closest to target ?

  • @anwarislive
    @anwarislive 2 ปีที่แล้ว

    Is this the best time complexity we can get?

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

    somw time u r best

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

    Thanks for this nice explanation

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

    It would be much better if you could write a cleaner code, it is not just about getting the code submitted.

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

    why we done minus target

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

      to fing the difference, or to find which is closest ..to find the distance

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

    why abs() is used? also why int start =num[i+1] rather than 0?please explain

    • @avibirla9863
      @avibirla9863 2 ปีที่แล้ว

      abs is absolute value ...if diff is -ve it will consider in +ve only

  • @nitinrai5053
    @nitinrai5053 2 ปีที่แล้ว

    amazing explanation

  • @stocks4Trading
    @stocks4Trading 2 ปีที่แล้ว

    Thanks a lot maam :)

  • @sculptandstyle_
    @sculptandstyle_ 2 ปีที่แล้ว

    Please make video on suduko solver and valid sudoko 🙏🙏🙏🙏

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

      Hey Shruti, thanks for asking, Sudoku solver video is already made:
      th-cam.com/video/eLhmZlsGmvE/w-d-xo.html

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

    ye kitti osm hai yaar 🥰

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

      Tum n aise hi kisi ke bhi comment ko like mat karte jao,
      Hame hope mil jati hai 🫣

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

      @@rohitthakre215 😂

  • @animeshpandey2911
    @animeshpandey2911 2 ปีที่แล้ว

    thanks a lot

  • @RajeshKumar._.16
    @RajeshKumar._.16 ปีที่แล้ว

    nice

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

    why diff = INT_MAX ?

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

      to find the minimum between two values , one should be bigger , but for the first element , there is no second valuw to compare , so we take maximum integer possible .

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

      @@shivamnegi7552 thank you vro

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

      @@techieworld4269 love you

  • @avibirla9863
    @avibirla9863 2 ปีที่แล้ว

    Good explanation. But your intendations are pretty weird !!!

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

    difficult to understand from this

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

    what is this test case failing can someone help?
    test case - [1,1,1,0] , target =-100
    my code->
    int diff=INT_MAX;
    for(int i=0;i