Given an array of N integers, you need to find the maximum element among them that is not a perfect square. If all the array elements are perfect squares, you should print -1.
The first line of the input contains a single integer T, denoting the number of test cases. Then T test cases follow. Each test case contains two lines of input:-
The size of the array N
The elements of the array separated by spaces.
For each testcase, print the maximum element of the array that is not a perfect square. If no such element exists, print -1.
16 20 25 2 3 10
0 1 4 9 16 25
For testcase 1: 20 is the greatest number in the array that is not a perfect square.
For testcase 2: All elements are perfect squares, hence we print -1.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.