Determine Count of Good Triplets
You are given two arrays ARR1
and ARR2
, containing N
and M
elements respectively. There are two types of 'good triplets' that need to be identified in these arrays.
Type 1: A triplet (i, j, k) where the square of ARR1[i]
equals the product of ARR2[j]
and ARR2[k]
. Indices follow the condition 0 ≤ i < N and 0 ≤ j < k < M.
Type 2: A triplet (i, j, k) where the square of ARR2[i]
equals the product of ARR1[j]
and ARR1[k]
. Indices follow the condition 0 ≤ i < M and 0 ≤ j < k < N.
Your task is to calculate the total number of such 'good triplets' for each test case.
Input:
The first line of input consists of an integer T
, representing the number of test cases. For each test case, the input is structured as follows:
- The first line contains two space-separated integers,
N
and M
, indicating sizes of ARR1
and ARR2
respectively.
- The second line contains
N
space-separated integers representing the elements of ARR1
.
- The third line contains
M
space-separated integers representing the elements of ARR2
.
Output:
For each test case, output a single integer on a new line, representing the total number of good triplets found according to the conditions specified. Each test case's output should be on a separate line.
Example:
Input:
1
2 3
3 4
1 2 4
Output:
3
Constraints:
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 100
- 1 ≤ M ≤ 100
- 1 ≤ ARR1[i] ≤ 10^4
- 1 ≤ ARR2[i] ≤ 10^4
- Time limit: 1 second
Note:
You do not need to print anything explicitly. Your task is to implement the given function and return the results as specified.
Calculate the total number of 'good triplets' in two arrays based on given conditions.
Iterate through all possible triplets in both arrays and check if they satisfy the conditions
Use nested loops to i...read more
Top LinkedIn Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month