Тёмный

Boats to Save People 

Kevin Naughton Jr.
Подписаться 138 тыс.
Просмотров 20 тыс.
50% 1

Опубликовано:

 

23 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 57   
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
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 года назад
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 4 года назад
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 лет назад
u made leetcode fun , thanks man
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
Thanks Derek I really appreciate that! That's exactly what I'm trying to do...make this stuff fun and understandable :)
@MGtvMusic
@MGtvMusic 3 года назад
@@KevinNaughtonJr Literally bro I don't think we appreciate you enough You literally made leetcode so much fun
@ankitagarwal4914
@ankitagarwal4914 4 года назад
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 лет назад
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 лет назад
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 лет назад
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 года назад
@@KevinNaughtonJr A very good answer to a very good question. Thanks both of you.
@sharinganuser1539
@sharinganuser1539 3 года назад
couple of questions: 1. what if heaviest +lowest is not the optimal solution (i.e heaviest+lowest
@rsifodias5
@rsifodias5 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.
@somujj
@somujj 5 лет назад
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.
@sahilarora1794
@sahilarora1794 5 лет назад
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.
@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!
@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.
@kridishuprety5199
@kridishuprety5199 3 года назад
Kevin is the OG
@raghvendratiwari7862
@raghvendratiwari7862 5 лет назад
Nice.you codes are simple to understand.thank you.
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
Anytime!
@justinf7438
@justinf7438 5 лет назад
Great Video! Super helpful and thoroughly explained as always
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
Thanks Spark I really appreciate it!
@kumaransg1828
@kumaransg1828 5 лет назад
hi kevin,need videos on segment trees and few leetcode problem based on them.
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
Hey Kumaran I'll see what I can do!
@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
@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
@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
@MadeByDAY
@MadeByDAY 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 😂
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
You're my BOY Dom
@bhaveshthawrani7383
@bhaveshthawrani7383 4 года назад
Can anyone tell how to deal with( [4,3,5,10,4,4] max weight limit =15) testcase
@kurdi_x5842
@kurdi_x5842 2 года назад
making sense
@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.
@antwanwimberly1729
@antwanwimberly1729 2 года назад
so sort the array and pair the heaviest w/ the lightest person af - #usa
@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 лет назад
That's ok it happens just keep working at it!
@atift5465
@atift5465 5 лет назад
@@KevinNaughtonJr will do Kevin!
@Firstusee256
@Firstusee256 5 лет назад
Great
@KevinNaughtonJr
@KevinNaughtonJr 5 лет назад
Dev- House thank you!!!
@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; } }
Далее
Count Primes
6:46
Просмотров 60 тыс.
The HARSH Reality of Working in Big Tech
8:42
Просмотров 22 тыс.
Unique Paths
7:07
Просмотров 60 тыс.
Next Closest Time
8:47
Просмотров 32 тыс.
Walls and Gates
8:09
Просмотров 40 тыс.
An Entire Computer Science Degree in 11 Minutes
11:13
Просмотров 834 тыс.
Working Remotely in my 20s as a Software Engineer
7:50
License Key Formatting
9:33
Просмотров 16 тыс.
Coin Change
10:16
Просмотров 154 тыс.
Girls Try Hacking for $100...It Gets WEIRD
8:03
Просмотров 23 тыс.