Company: Microsoft
Difficulty: medium
Longest Square Chain Subset Given an array B , choose the largest possible subset of indices such that, after sorting the chosen values in nondecreasing order, every value after the first is the square of the preceding value. Input The first line contains N . The second line contains N positive integers. Output Print the maximum subset size. Constraints 1 <= N <= 200000 1 <= B[i] <= 1000000000 Example Input: 7 2 4 16 3 9 5 25 Output: 3 Notes The subset uses array indices, so equal values have their original multiplicity. Since 1^2 = 1 , all occurrences of 1 may appear in one chain. Values greater than 1 cannot repeat consecutively in a valid chain.