I am prepping for an interview and I am trying to solve this question.
I want to know if I can find integers x, y, and z to satisfy the following equation without using any python modules.
4x + 6y + 11z = 31
I can come up with a solution that is O(n^3) by limiting the value of either x, y, or z by 31/coefficient. I am wondering if there is a more efficient way.
def isValid(denoms, target):
maxX = target//denoms[0]
maxY = target//denoms[1]
maxZ = target//denoms[2]
for x in range(maxX):
for y in range(maxY):
if ((x * denoms[0]) + (y * denoms[1]) > target):
break
z = target - (denoms[0] * x) - (denoms[1] * y)
if int(z) == z:
return True
return False
print(isValid([4, 6, 8], 35))