first and second. Count index triples of two kinds:
- (i, j, k) with first[i]² == second[j] * second[k] and j < k;
- (i, j, k) with second[i]² == first[j] * first[k] and j < k.
In other words, the square of a number from one array must equal the product of two elements at different positions of the other array. Return the total number of such triples of both kinds.first=[6, 3], second=[4, 9, 12, 1] → 2
6² = 36 = 3 · 12 and 3² = 9 = 9 · 1: two triples with the square taken from first. None work the other way: for instance, 4² = 16, while the only pair product in first is 18.
first=[2, 2], second=[2, 2] → 4
Each of the four 2s squared gives 4, which equals the product of the one pair in the other array: 4 triples.
first=[5], second=[7] → 0
Each array has a single number, so no pair can be formed.
first=[6, 3], second=[4, 9, 12, 1]
2
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.