Skip to content

Latest commit

 

History

History

Dutch National Flag Problem

Given an array containing three objects, labled as 0, 1 and 2

Sort this array in-place

  • arr = [2, 0, 2, 1, 1]
  • Output: [0, 1, 1, 2, 2]

Task:

  • Following two-pointers pattern, to solve this problem without any extra space

Exercise: DutchFlag.py

Time complexity: O(n), n as the length of input array

Space complexity: O(1), no extra space

Constraints:

  • 1 <= arr.length <= 1000
  • 0 <= arr[i] <= 2

《BACK》