Boats to Save People

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

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

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

    THANKS FOR 3K

    • @morganadriel9720
      @morganadriel9720 3 ปีที่แล้ว

      sorry to be offtopic but does any of you know a method to get back into an instagram account??
      I somehow lost my account password. I would love any help you can offer me!

    • @kysonbruce1767
      @kysonbruce1767 3 ปีที่แล้ว

      @Morgan Adriel instablaster :)

    • @morganadriel9720
      @morganadriel9720 3 ปีที่แล้ว

      @Kyson Bruce I really appreciate your reply. I found the site on google and I'm in the hacking process now.
      I see it takes quite some time so I will reply here later when my account password hopefully is recovered.

    • @morganadriel9720
      @morganadriel9720 3 ปีที่แล้ว

      @Kyson Bruce it worked and I finally got access to my account again. I am so happy:D
      Thanks so much you really help me out :D

    • @kysonbruce1767
      @kysonbruce1767 3 ปีที่แล้ว

      @Morgan Adriel Glad I could help :D

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

    Thanks a ton Kevin - was stuck trying to solve this with a recursive approach. Was getting complicated with only 40% test cases passing. Your explanation and approach helped immensely! :-)

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

    Thank you for everything, Kevin. Also liked that you talked about time and space complexity in the end. Can you please talk about these in every video. That would be really helpful. Thanks again!

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

    u made leetcode fun , thanks man

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

      Thanks Derek I really appreciate that! That's exactly what I'm trying to do...make this stuff fun and understandable :)

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

      @@KevinNaughtonJr Literally bro I don't think we appreciate you enough You literally made leetcode so much fun

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

    Funny thing to share: I fainted twice but expressions in both were opposite - "Looking at the prompt I fainted, looking at the explanation in less than 7 mins fainted again" LOL!!.... thanks for spreading knowledge!!

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

    Small optimization: since we know the range of values (every person has a weight between 0 and limit) we can sort with counting sort -> O(n + limit) time, O(limit) space.

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

    I feel like there are so many different kinds of questions people can ask as leetcode has 1000+ problems. Besides studying the higher frequency ones, how do you remember specific techniques? Like sometimes I forget how to do longest palindromic subsequence. And then I go in a rabbit hole of just being frustrated with not remembering everything I learn even if I understand the code. I don't wanna say to memorize but to some extent do you have a main bank of high value questions that you just need to know front and back?

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

      Hey Frank I know what you mean...there are so many problems and it can def be overwhelming at times. Like you said I don't really suggest memorizing, but I would suggest (similar to what you're saying about understanding a bank of questions) understanding / knowing certain algorithms / techniques that you can apply to a handful of problems. I hope this helps and lmk if you have any other questions and as always thanks for your support!

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

      @@KevinNaughtonJr A very good answer to a very good question. Thanks both of you.

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

    hi, i tried the same logic but it doesnt work for on leet code for the following test data
    [44,10,29,12,49,41,23,5,17,26]
    50
    can you let me know if you checked this test case ?
    i have been beating my head on this for a few days.

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

    I have one question for u
    What if we try to fit heaviest with the next heaviest fit in boat.
    Isnt this should work

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

      I tried it , it is a good approach but it does not work , As it does not result in optimal pickup of pairs.

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

    All that he said in Nice and Simple way.
    let me explain the proof in a very simple way:
    we sorted the people by their weight......then there are two cases:
    CASE-I: "minimum weight" man can't sit with "maximum weight" man
    it implies that "maximum weight" man can't sit with any other man
    hence "maximum weight" man sits alone so decrement only high-end pointer.
    CASE-II: "minimum weight" man can sit with "maximum weight" man
    it implies that "minimum weight" man can sit with any other man
    since we want to maximize the amount of weight carried by a single boat we sit "minimum weight" man and "maximum weight" man together.
    so increment low-end pointer and decrement high-end pointer.

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

    couple of questions:
    1. what if heaviest +lowest is not the optimal solution (i.e heaviest+lowest

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

      For 1) It's not a huge consideration in this case. Suppose we have weights [ 2, 4, 6 ] with limit 10. While technically, [ 4, 6 ] is a more optimal boat than [ 2 , 6 ], since there's only space for 2 people, there have to be 2 boats going out anyways. It doesn't matter is the last boat is being carried out by [2], or [4].
      However, for 2) the optimization becomes a lot harder. What you would do is "bounce" between the lowest and highest pointers. Imagine weights [2, 4, 6, 10], with limit = 10, and k = 3. First, you'd fill 1 boat with 10, move to index with 6. Now that the boat is full, initialize a second boat, and fill it with the right (6), and the left (2). Move both your pointers. Now, attempt to fill your boat either with the highest value (4), or the lowest value (4). In our case, these values are the same, so we exit with 2 boats.

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

    hi kevin,need videos on segment trees and few leetcode problem based on them.

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

      Hey Kumaran I'll see what I can do!

  • @TravelWithAmitDubey
    @TravelWithAmitDubey 4 ปีที่แล้ว

    Hi Kevin,
    Thanks for giving your support to open world, your videos are really awesome.

    • @KevinNaughtonJr
      @KevinNaughtonJr  4 ปีที่แล้ว

      Thanks Amit and anytime happy to help!

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

    Great Video! Super helpful and thoroughly explained as always

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

      Thanks Spark I really appreciate it!

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

    Nice.you codes are simple to understand.thank you.

  • @noahmatisoff9518
    @noahmatisoff9518 5 ปีที่แล้ว

    Wouldn't it be using extra memory based on memory usage of the underlying Java sort algorithm?

    • @KevinNaughtonJr
      @KevinNaughtonJr  5 ปีที่แล้ว

      Good point, really depends on that underlying algorithm like you mentioned. Off the top of my head, in Java, I believe it's using quick sort or some hybrid between quick sort and tim sort so I don't believe we'd be using extra memory but correct me if you think I'm wrong :)

    • @noahmatisoff9518
      @noahmatisoff9518 5 ปีที่แล้ว

      @@KevinNaughtonJr the sort you're using defined by java.util.Arrays actually uses two sorts like you mentioned, quicksort for primitives and merge sort for objects using a comparator. In this case, it would use quicksort which uses log(n) memory, but I believe you said constant memory around 6:18. TIL

  • @dmitrykarpenko2271
    @dmitrykarpenko2271 5 ปีที่แล้ว

    Faster than 14.88% solutions? Did the sorting take too much time?

    • @espressothoughts
      @espressothoughts 5 ปีที่แล้ว

      Yeah it was probably the sorting but that's what makes this algorithm work.
      I think another way to do it without sorting is to use a hashmap where through one pass you can go through the unsorted peoples list. You can store the complement that can add up to the i-th's numbers limit as well as the number you're currently on together.
      This way you only go through the array once

  • @kridishuprety5199
    @kridishuprety5199 3 ปีที่แล้ว

    Kevin is the OG

  • @bhaveshthawrani7383
    @bhaveshthawrani7383 4 ปีที่แล้ว

    Can anyone tell how to deal with( [4,3,5,10,4,4] max weight limit =15) testcase

  • @codestorywithMIK
    @codestorywithMIK 4 ปีที่แล้ว

    Very well explained

    • @KevinNaughtonJr
      @KevinNaughtonJr  4 ปีที่แล้ว

      thanks Mazhar! If you like my explanations be sure to check out the interviewing service I created thedailybyte.dev/?ref=kevin I recommend joining the annual plan if you can!

  • @JohnWick-dy4hg
    @JohnWick-dy4hg 3 ปีที่แล้ว

    I have solved it before 4.03, thanks kevin for providing me the hint

  • @pratheek5096
    @pratheek5096 4 ปีที่แล้ว

    IT WOULD REALLY HELP IF YOU DIDN'T NAVIGATE AWAY FROM THE CODE AND GET A CLOSE UP ON YOUR FACE EVERYTIME YOU WANT TO EXPLAIN SOMETHING. cos some ppl would like to keep seeing the code while you're explaining .....PS: Like Nick White Does...plss implement this.

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

    > Everyone Dies™ ✅
    > putting problem intuition in video description ✅
    > describing time and space complexities ✅
    > mixing it up and using a new outro song ✅
    You die in the game, you die in real life. Gotta simulate real life to where if you can't solve leetcode problems in production, people die!!! 😱
    Good video though 😂

  • @antwanwimberly1729
    @antwanwimberly1729 3 ปีที่แล้ว

    so sort the array and pair the heaviest w/ the lightest person af - #usa

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

    making sense

  • @atift5465
    @atift5465 5 ปีที่แล้ว

    If only I came up with that algorithm Need to spend more time analyzing the problem and not always going for brute force. My code became extremely long and complex to a point where I couldnt trace lol.

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

      That's ok it happens just keep working at it!

    • @atift5465
      @atift5465 5 ปีที่แล้ว

      @@KevinNaughtonJr will do Kevin!

  • @thedataguyfromB
    @thedataguyfromB 3 ปีที่แล้ว

    Considering All Possible Cases
    class Solution
    {
    public int numRescueBoats(int[] p, int limit)
    {
    Arrays.sort(p);
    int l=0;
    int h=p.length-1;

    int count=0;
    while(llimit)
    {
    count++;
    h--;
    }
    else
    {
    count++;
    l++;
    h--;
    }
    }

    return count;
    }
    }

  • @Firstusee256
    @Firstusee256 5 ปีที่แล้ว

    Great