I basically trying to test given two array A and B. Does B contain squares of every integer in A . So given A any five integers (even duplicates) is there a square of the integer in B.
A [ 2 3 3 4 1 1] - > B [4 9 9 16 1 1 ]
As I now understand it, you want an efficient algorithm so that, given two arrays of integers, A and B, you can determine whether ... what? Is it whether the square of each element of A occurs
somewhere within B (so that you are treating them as sets rather than arrays, in which order matters)? That is not what your steps do.
If you are thinking that the sum of two arrays of squares can't be the same unless the squares individually are the same, the answer is no. For a simple
counterexample, the sums 7^2 + 24^2 = 625 and 15^2 + 20^2 = 625 are equal, though the squares are different.
I'm not sure you've yet stated what the algorithm has to do. In your example, would you want to say yes or no if we replaced one of the 9's in B with, say, 10, or 25, or just removed it entirely? Then the square of everything in A would be in B (which is the condition you state), but not everything in B would be the square of something in A. I suspect you may want to determine whether B is a
permutation of the squares of elements of A (treated as a multiset); I'd search for such algorithms, if I were you.