why cant i use bubble_sort or insertion_sort as they both have order n complexity
Sorting in order n
Hey, instead of writing that much complex code, what you can do is count number of 0 , 1 and 2.
Add the number of 0 first then 1 then 2.
It will be a lot more easier to implement and it is O(N) time complexity and constant space
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.