Skip to content

Instantly share code, notes, and snippets.

@prasadwrites
Created April 30, 2021 03:37
Show Gist options
  • Select an option

  • Save prasadwrites/a04da1bac2475b822e7229e59256908f to your computer and use it in GitHub Desktop.

Select an option

Save prasadwrites/a04da1bac2475b822e7229e59256908f to your computer and use it in GitHub Desktop.
arr = ['G','B','R','G','B','G','R']
ridx=0
bidx=len(arr)-1
i=0
while(i<bidx):
if(arr[i] == 'R'):
arr[i],arr[ridx] = arr[ridx],arr[i]
ridx += 1
i = i+1
elif (arr[i] == 'B'):
arr[i],arr[bidx] = arr[bidx], arr[i]
bidx -= 1
else:
i=i+1
print(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment