Directi Interview Question
Software EngineersCountry: India
Interview Type: Written Test
def does_beat(Z, Y):
if len(Z) != len(Y):
raise BadParameter()
if len(Z) == 0:
return True
Z = sorted(Z)
Y = sorted(Y)
y_beats_z = -1
for i in range(len(Z)):
if Z[i] < Y[i]:
if y_beats_z == 1:
return False
y_beats_z = 0
elif Z[i] > Y[i]:
y_beats_z = 1
if y_beats_z == 0:
return False
return True
O(n) solution
y = [int(i) for i in input().split()]
z = [int(i) for i in input().split()]
my, My = min(y), max(y)
mz, Mz = min(z), max(z)
if My >= mz or Mz >= my:
print('True')
else:
print('False')
[1] Sort Y in ascending and Z in descending order. Check if Z beats Y, return true.
- Coder January 10, 2019[2] Sort Z in descending and Y in ascending order. Check if Y beats Z, return true.