Problem · Array

Equation Tuple Combination

Learn this problem
MediumZoox logoZooxFULLTIMEONSITE INTERVIEW

Problem statement

You are given an integer array numbers. Determine whether four distinct indices can fill the roles x, y, k, and b so that y = k * x + b.

  • Each role must use a different array index.
  • Equal numeric values may fill different roles only when they come from different occurrences.
  • Evaluate the equation exactly with signed 64-bit intermediate arithmetic.

Return true when at least one qualifying tuple exists. Otherwise, return false.

Function

hasEquationTuple(numbers: int[]) → boolean

Examples

Example 1

numbers = [1,2,3,5]return = true

Use four distinct occurrences: x = 1, k = 2, b = 3, and y = 5. They satisfy 5 = 2 * 1 + 3.

Example 2

numbers = [1,2,4,10]return = false

No assignment of the four distinct occurrences to x, y, k, and b satisfies the equation.

Example 3

numbers = [2,2,3,7]return = true

The two separate occurrences of 2 may fill x and k. With b = 3 and y = 7, the equation is 7 = 2 * 2 + 3.

Constraints

  • 0 <= numbers.length <= 250
  • -1000000000 <= numbers[i] <= 1000000000
  • All multiplication and subtraction must use signed 64-bit intermediate arithmetic.

More Zoox problems

drafts saved locally
public boolean hasEquationTuple(int[] numbers) {
    // Write your code here.
}
numbers[1,2,3,5]
expectedtrue
checking account