Grokking Oracle Coding Interview

0% completed

Hidden Document
Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content

.....

.....

.....

Like the course? Get enrolled and start learning!
Mohammed Dh Abbas

Mohammed Dh Abbas

· 2 years ago

class Solution: def sort(self, arr): b, m, e = 0, 0, len(arr) - 1 while m <= e: if arr[e] == 2: e -= 1 elif arr[b] == 0: # here is the tricky part if the middle pointer at same position as the position as the beginning pointer # and the beginning pointer = 0 it meas we are done with that part of the array so we can safely # move the middle pointer too together with the beginning pointer if m == b: m += 1 b += 1 elif arr[m] == 1: m += 1 elif arr[e] < arr[m]: # swap arr[e], arr[m] = arr[m], arr[e] elif arr[m] < arr[b]: # swap arr[m], arr[b] = arr[b], arr[m] return arr