Juniper Networks interview question

Given an array of 3 numbers how do you sort them without using any comparison operator. Write the code.

Interview Answer

Anonymous

Aug 25, 2016

def smallest(x,y,z): s = 0 m = 0 b = 0 while x and y and z: x -= 1 y -= 1 z -= 1 s += 1 m += 1 b += 1 if x == 0: while y and z: y -= 1 z -= 1 m += 1 b += 1 if y == 0: b += z if z == 0: b += y if y == 0: while x and z: x -= 1 z -= 1 m += 1 b += 1 if x == 0: b += z if z == 0: b += x if z == 0: while y and x: y -= 1 x -= 1 m += 1 b += 1 if y == 0: b += x if x == 0: b += y return (s,m,b) result = smallest(15,8,17) print(result)