Skip to main content
All Questions

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.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.