Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For every value y, how can you find the number of values x (0 ≤ x, y ≤ n - 1) such that x appears before y in both of the arrays?
Similarly, for every value y, try finding the number of values z (0 ≤ y, z ≤ n - 1) such that z appears after y in both of the arrays.
Now, for every value y, count the number of good triplets that can be formed if y is considered as the middle element.