![]() |
VOOZH | about |
Given two arrays arr1[] and arr2[] of length N which contains Numerator and Denominator of N fractions respectively, the task is to count the number of fractions from the array which is a perfect square of a fraction.
Examples:
Input: arr1[] = {3, 25, 49, 9}, arr2[] = {27, 64, 7, 3}
Output: 2
Explanation:
(arr1[0] / arr2[0]) = (3 / 27) = (1 / 9) = (1 / 3)2
(arr1[1] / arr2[1]) = (25 / 64) = (5 / 8) 2
(arr1[0] / arr2[0]) and (arr1[1] / arr2[1]) are perfect square fractions. Therefore, the required output is 2.Input: arr1[] = {1, 11, 3, 9}, arr2[] = {9, 11, 5, 1}
Output: 3
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
2
Time Complexity: O(N * log(M)), where M is the maximum element from both the arrays.
Auxiliary Space: O(1)