Question DSA-SORT-0062
HardWhat is the output of this code?
def part(a, lo, hi):
p = a[(lo + hi) // 2]; i, j = lo - 1, hi + 1
while True:
i += 1
while a[i] < p: i += 1
j -= 1
while a[j] > p: j -= 1
if i >= j: return j
a[i], a[j] = a[j], a[i]
a = [5, 3, 8, 4, 2, 7, 1, 6]
k = part(a, 0, len(a) - 1)
print(k, a)
- A.
3 [1, 2, 3, 4, 5, 6, 7, 8]
- B.
4 [1, 3, 2, 4, 8, 7, 5, 6]
- C.
Sign up free to see the answer and a step-by-step explanation.