Sort Colors Problem

Sort Colors Problem — ExecCode Easy DSA Practice

Solve the Sort Colors problem on ExecCode. Free online easy DSA practice in Sort. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Sort an array containing only 0, 1, and 2 in place. Use low for the next 0 position, mid for the current unknown value, and high for the next 2 position.

Examples

Input nums = [2,0,2,1,1,0]; Output [0,0,1,1,2,2]. Input nums = [2,0,1]; Output [0,1,2]

Constraints

n == nums.length 1 ≤ n ≤ 300 nums[i] is 0, 1, or 2

Practice Sort Colors free on ExecCode. Browse DSA problems, topic map, and placement guides.