Find the maximum number of pairs whose product is not a perfect square after at most k changes.
Unlock detailed company stats for this questionUpgrade
A teacher assigns random numbers to students. Two students can be paired if the product of their numbers is not a perfect square. Each student can participate in at most one pair. Complete the function getNonPerfectPairs(int arr[n], int k) returning the number of non-perfect pairs. Constraints: 1 <= n <= 10^5; 1 <= arr[i] <= 10^6; 0 <= k <= n. Example: arr = [4, 12, 20, 5, 20, 5], k = 1 -> 3 (pair 4 and 5; pair 12 and 20; change one 20 to 11 and pair 11 and 5). Sample: arr = [2, 18, 3, 50, 8, 32], k = 1 -> 2 (pair 3 and 2; change 50 to 1 and pair 1 and 32). Sample 2: arr = [1, 2, 3, 4, 5], k = 2 -> 2 (pair 1 and 2; pair 3 and 4).
Format · Microsoft OA.
Community answers
No answers contributed by the community yet.


