5.1 The Dutch National Flag Problem Brute Solution


I implemented a brute force solution that follows the one mentioned in the text, but during the EPI Judge, I get a failed test:

“Test FAILED ( 2/204) Not partitioned after 2th element
A: [1, 1, 0, 2]
pivot_idx: 1
Failure info explanation: Basic test, one swap”

However, my final result is a correctly rearranged array. Would anyone know why the test fail despite the final array being correct? Code is followed below:

def dutch_flag_partition(pivot_index, A):
# TODO - you fill in here.
L = []
E = []
G = []

pivot = A[pivot_index]

for i in range(len(A)):
    if A[i] < pivot:
    elif A[i] == pivot:
    elif A[i] > pivot:
    else: return -1

A = (L + E + G)

return A


Please post your result.