Equation Tuple Combination
Updated
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[]) → booleanExamples
Example 1
numbers = [1,2,3,5]return = trueUse 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 = falseNo assignment of the four distinct occurrences to x, y, k, and b satisfies the equation.
Example 3
numbers = [2,2,3,7]return = trueThe 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 Onsite Interview questions
Similar questions at other companies
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
- Unique Near-Equal Target-Sum PairsFivetran · ONSITE INTERVIEWFivetran interview questions
- Minimum Unique Card Suffix LengthBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Count Pairs Divisible by KApple · ONSITE INTERVIEWApple interview questions
- Digit-Reversed Pairs in an ArrayExpedia · ONSITE INTERVIEWExpedia interview questions
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Majority ElementMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Count Index Pairs with Equal Value OffsetGoogle · ONSITE INTERVIEWGoogle interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions