Counting Sort - O(n) Solution to Sort Colors - Leetcode 75

preview_player
Показать описание
Counting Sort - O(n) Solution to Sort Colors - Leetcode 75

#coding #leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

it uses two loops one for counter and then for overwrite

you can use one loop go through the arr at once store the index of last white and other colors
when you get the new color of current index you just add it to the index after the last index of so far that color and update it

it's the fastest way

CC.unposted
Автор

We can use Dutch national flag algorithm which is more efficient than counting sort which takes time and space complexity : O(n) and O(1)🎉

thesandyff
Автор

I used the dutch national flag algorithm 😭

PhilaDlamini-ox
Автор

I got made when I heard bubble sort for this.

Hardcore_Remixer
Автор

This sorting only works for a small range of numbers in the array. If we have numbers n from 1 to 10⁹, the complexity of the algorithm will not be O(n), but O(n + 10⁹), so u should use this sorting only in small ranges

no_name
Автор

Good video but bro is going though puberty at age 40 😂

eshuapoorv
Автор

Is it normal that i thought of this as my first solution

Ankumeh
Автор

That one pass through the array to count the variables is O(n)? No? So how can the solution be O(1)?

a-baby
Автор

Can i use the hashmap ??? 😢😢😢 It takes 0(n) rught?

adithyabablu
Автор

Dutch National Flag Algorithm better for this problem

otabekaynazarov
Автор

radix sort with an occurrence array of 3 ... ez pz

YouGotexpressurself
Автор

Hmm. Questionable phrasing in the beginning.😂

rjkgaming
Автор

These Leetcode questions are the most useless things ever. I make 10x the amount of money cause I proved practical application of usable solutions in my interviews versus ridiculous Leetcode solutions that serve no purpose in in system design.

jimbo
Автор

American cops can get jobs at Amazon ig?

sandwitchchan
Автор

How are you still having voice breaks in your 30s

AnEntityBrowsingYT
welcome to shbcf.ru