Question DSA-ARR-0065
HardWhat is the output of this code?
m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
out = []
t, b, l, r = 0, 2, 0, 2
while t <= b and l <= r:
out += m[t][l:r + 1]; t += 1
out += [m[i][r] for i in range(t, b + 1)]; r -= 1
if t <= b:
out += m[b][l:r + 1][::-1]; b -= 1
if l <= r:
out += [m[i][l] for i in range(b, t - 1, -1)]; l += 1
print(out)
- A.
[1, 2, 3, 6, 9, 7, 8, 4, 5]
- B.
[1, 4, 7, 8, 9, 6, 3, 2, 5]
- C.
Sign up free to see the answer and a step-by-step explanation.