LeetCode Sort Colors Solution Explained - Java

  Рет қаралды 31,905

Nick White

Nick White

4 жыл бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow My Twitter - / nicholaswwhite
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 59
@palak2708
@palak2708 4 жыл бұрын
"It's pretty easy, honestly", kills me from within.
@neosapien247
@neosapien247 3 жыл бұрын
Look at the number of times he's tried it when he hits submit.
@nev861
@nev861 2 жыл бұрын
@@neosapien247 lmao
@jamjam3448
@jamjam3448 Жыл бұрын
😂 😂 😂 Me tooo. I found it so difficult
@danieltannor6647
@danieltannor6647 4 жыл бұрын
I don't think this is an easy question. It might be a good idea to try to explain how someone could think about the problem and reach the answer, instead of trying to explain a prepared answer. Also, an explanation about how we know the correctness for the solution - how do we know it will always work?
@arnavkarforma3015
@arnavkarforma3015 4 жыл бұрын
That's all about these kinds of questions, you don't need to reinvent the wheel in an interview. Just need to practice enough and train your brain for this shit.. if you think you can you can think through an unseen question in 45 mins you must be a super genius..
@galwije
@galwije 2 жыл бұрын
@@arnavkarforma3015 it is so lame that FANG want to hire people who like parrots just memorize problems. fk FANG I am going to make a living using my brain
@tanishq2766
@tanishq2766 Жыл бұрын
@@galwije Ikr Mate! :( That's just so saddening smh :(
@nishantkumarbundela8482
@nishantkumarbundela8482 4 жыл бұрын
5:38 Happens to me every time I give an exam lol.
@darod6098
@darod6098 4 жыл бұрын
I can't decide if you saying "it's pretty easy" in most problems is super annoying o super helpful to think it as an easy problem hahaha. Thank for your work bro!
@randeepsiddhu
@randeepsiddhu 4 жыл бұрын
Looking at your videos Nick, I can tell you are a very honest man!
@calfland79
@calfland79 4 жыл бұрын
Great tutorial. just two points: 1) in the while loop condition, start
@drj7714
@drj7714 3 жыл бұрын
well, index < end won't work had to do index
@adil_k
@adil_k 2 жыл бұрын
Your ability to explain things is amazing.
@babumon5351
@babumon5351 4 жыл бұрын
Thanks for helping me.
@ousmandiallo761
@ousmandiallo761 4 жыл бұрын
BARS haha.. your'e the man dude. I could totally see myself chilling with you at work talking random shit
@AngadSingh97
@AngadSingh97 4 жыл бұрын
Great video Nick, as always
@shashankmaurya4673
@shashankmaurya4673 2 жыл бұрын
Thank you for your help, your videos helps me a lot.
@pete_win
@pete_win 2 жыл бұрын
Good video Nick. Just a heads up for others, If you're going to use a sorting algorithm, bucket sort makes the most sense (linear time) in this scenario as the numbers being sorted are known up front (0,1,2).
@sehejwahla5437
@sehejwahla5437 3 жыл бұрын
Great work bruh . Keep up!!
@manojg4451
@manojg4451 4 жыл бұрын
Love the readability of the code :)
@NickWhite
@NickWhite 4 жыл бұрын
thanks dude
@musafirhainyaaron1720
@musafirhainyaaron1720 4 жыл бұрын
The condition in while should be = while(start < end && index < end) ?
@namanshah9216
@namanshah9216 4 жыл бұрын
index should reach till the end, that's why index
@himanshusharma261
@himanshusharma261 2 жыл бұрын
thanks for wonderful explanation 🙏
@jeezradz
@jeezradz 4 жыл бұрын
how do you decide on the pivot value of 1? What if there were 4 different elements in the array and we had to sort -- how can you decide on the pivot value then?
@fantasy9960
@fantasy9960 Жыл бұрын
really helpful, thank you!
@gangu749
@gangu749 2 жыл бұрын
That brain pause happens with all of us Nick , Don't worry about it 😃
@shahbazalam4565
@shahbazalam4565 4 жыл бұрын
Ok i get it why the index should not be incremented when checking last element but that honestly is "NOT AT ALL EASY" to imagine intuitively.
@kalyanvejalla
@kalyanvejalla 3 жыл бұрын
Dude youre so awesome!
@parvezrafisparta
@parvezrafisparta 4 жыл бұрын
Good one dude
@shivanshbhardwaj5841
@shivanshbhardwaj5841 3 жыл бұрын
Thanks Bro!
@khakr01
@khakr01 4 жыл бұрын
Do we really need the condition start < end condition in while loop? At any point, it cannot be more than index.
@sakshigupta7616
@sakshigupta7616 4 жыл бұрын
It's true we don't really need it but it surely does speed up the processing. I tested both ways in one I used it I got 0ms and in the one I didn't use it I got 4 ms. I don't understand why exactly that happened, tell me if someone gets it
@tomilui2707
@tomilui2707 3 жыл бұрын
can somebody explain why while (index < end) wont work but only (index
@shusenacademy
@shusenacademy 3 жыл бұрын
I still dont understand why both index and start need to add 1 when nums[index] == 0 and after the swap ?
@sehejwahla5437
@sehejwahla5437 3 жыл бұрын
Cool bro !! Thanx
@juanguang2076
@juanguang2076 4 жыл бұрын
seems like the condition while(index
@drj7714
@drj7714 3 жыл бұрын
yeah, that's because you need to swap when index=end. to understand take for example 02001.
@reaperforever8478
@reaperforever8478 3 жыл бұрын
But isn't changing the array so much taxing on the cpu cycles ? I had like idea of just having 3 temporary arrays , just pushing 0 , 1 , 2 in each of the arrays then just joining the arrays after going through the whole list
@challengeyourmind3937
@challengeyourmind3937 2 жыл бұрын
It says to solve in-place
@sivaprasadneelur3171
@sivaprasadneelur3171 3 жыл бұрын
Its not working for some of the inputs may please check -> input = { 0, 2, 1, 0, 1, 2, 1, 2, 1, 0 };
@lipishah474
@lipishah474 4 жыл бұрын
if the input is like {2,0,1}.. I think for this scenario this code is not working. Could you please help to fix that?
@navneetkhandelwal5447
@navneetkhandelwal5447 4 жыл бұрын
follow geeks for geeks method
@buggy_bug
@buggy_bug 4 жыл бұрын
it does work
@nanlala3171
@nanlala3171 3 жыл бұрын
why cannot just remove index++ at line #14
@tongl7380
@tongl7380 2 жыл бұрын
HAHA, it's cute that you keep explaining your head blinded LOL
@debanjanasantra6724
@debanjanasantra6724 2 жыл бұрын
Cool!
@wilsonwang8641
@wilsonwang8641 2 жыл бұрын
Your long sigh at 5:44 make me laugh😄That's a really status that leetcoders can't remember why the passed solution works.
@monkey73921
@monkey73921 3 жыл бұрын
0 1 2 red white blue, bars. Lmao
@ColdIce99
@ColdIce99 2 жыл бұрын
How could you get this in 20 mins in an interview if you never have seen this before. Even if you understand pointers it would take a typical person may 45 to an hour at the whiteboard to draw out the solution.
@oscaropdyou
@oscaropdyou 4 жыл бұрын
This is the standard "The Dutch National Flag problem". And there are better standard less-complex solution.
@jshpro3
@jshpro3 2 жыл бұрын
turn off stereo on the blue yeti or put it in front of you man 😂
@seal0118
@seal0118 3 жыл бұрын
if you solved the national dutch flag problem before, this problem wont even take 10 seconds to solve
@zykssa1715
@zykssa1715 2 жыл бұрын
After solving 9 times, you cant call it easy. Also, got a answer wrong 2 times after submission, Means worked for base case and did not some other case. :D . Cant brag it is easy dude.
@galwije
@galwije 2 жыл бұрын
So you first spit out the solution and then try to comprehend what you just did. Tell al the dudes that this is about memorization and reread just like you just figured it out.
@agbaid
@agbaid Жыл бұрын
Easy with the "pretty easy" statements. Sounds condescending
@PrashantKumar-gg5qd
@PrashantKumar-gg5qd 3 жыл бұрын
Why are u killing mosquito?
LeetCode 33. Search in Rotated Sorted Array
9:30
Nick White
Рет қаралды 97 М.
LeetCode 56. Merge Intervals (Algorithm Explained)
12:57
Nick White
Рет қаралды 89 М.
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 12 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 93 МЛН
Sort Colors - Quicksort Partition - Leetcode 75 - Python
15:48
LeetCode 75. Sort Colors  [Solution + Code Explained ]
8:20
jayati tiwari
Рет қаралды 4,7 М.
LeetCode Reorder List Solution Explained - Java
12:55
Nick White
Рет қаралды 31 М.
LeetCode 763. Partition Labels (Solution Explained)
12:56
Nick White
Рет қаралды 16 М.
LeetCode 525. Contiguous Array (Algorithm Explained)
9:54
Nick White
Рет қаралды 36 М.
LeetCode Minimum Size Subarray Sum Solution Explained - Java
8:36
Sort Colors | leetcode 75 | Hindi
10:31
Codebix
Рет қаралды 6 М.
Learn Quick Sort in 13 minutes ⚡
13:49
Bro Code
Рет қаралды 301 М.
НЕ ПОКУПАЙ СМАРТФОН, ПОКА НЕ УЗНАЕШЬ ЭТО! Не ошибись с выбором…
15:23
Как правильно выключать звук на телефоне?
0:17
Люди.Идеи, общественная организация
Рет қаралды 727 М.
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 6 МЛН
Опыт использования Мини ПК от TECNO
1:00
Андронет
Рет қаралды 766 М.
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 38 МЛН
Первый обзор Galaxy Z Fold 6
12:23
Rozetked
Рет қаралды 401 М.