DEV Community

Sort Colors - LeetCode

Subramanya Chakravarthy on June 12, 2020

Given an array of three group of elements sort them in order Input: [2,0,2,1,1,0] Output: [0,0,1,1,2,2] One Simple way is to use Counting Sort a...
Collapse
 
ravi1512 profile image
Ravi Mishra

I implemented these two methods exactly. First one has an extra space of O(n) and the other one is constant space O(1). Runtime of both functions is O(n). This problem is also called Dutch National Flag problem.