Given an array nums with n objects colored red (0), white (1), or blue (2), sort them in-place so that objects of the same color are adjacent, in the order red, white, and blue. You must solve this without using the library's sort function.
nums = [2,0,2,1,1,0][0,0,1,1,2,2]Invariant: [0..lo-1] all 0s, [lo..mid-1] all 1s, [hi+1..n-1] all 2s. When mid sees 0, swap with lo (known 1) — both advance. When 2, swap with hi (unknown) — only hi shrinks since new value at mid is unclassified. When 1, just advance mid.