I had to admit that I spent a lot of time thinking about 'Color Sort' and 'findKthLargest' problems. Here are tips about the relations.
- Three different colors are similar to elements smaller than pivot, elements equal to pivot, and elements larger than pivot;
- The mapping indices is just the order to traverse the numbers;
- There cannot be an element appears more than (len+1)/2 times, so we must find the median at fist;