Interview Questions/Coding/Square Product Signal Pairs

Square Product Signal Pairs

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Square Product Signal Pairs

Two calibration teams, Alpha and Beta, submit positive integer signal strengths. A suspicious calibration record is formed when one signal from one team can be explained as the geometric center of two distinct signals from the other team. More precisely, one Alpha signal can be paired with two different Beta indices when beta[x] multiplied by beta[y] equals alpha[i] squared. Similarly, one Beta signal can be paired with two different Alpha indices when alpha[x] multiplied by alpha[y] equals beta[i] squared. Different index choices count separately, even if the numeric values are the same. Input Format: You are given arrays alpha and beta. Output Format: Return the total number of suspicious calibration records.

Examples

Example 1
Input:
alpha = [7, 4]
beta = [5, 2, 8, 9]
Output:
1

Explanation: alpha[1]=4 with beta[1],beta[2]. Total suspicious records = 1, so the output is 1.

Approach hint

Turn product of two numbers into a complement lookup.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp