Rice Bags
You are shopping on Amazon.com for some bags of rice. Each listing displays the number
of grains of rice that the bag contains. You want to buy a perfect set of rice bags.
From the entire search results list, riceBags. A perfect set of rice bags,
perfect, is defined as:
perfect are sorted in increasing order by grain count,
it satisfies the condition perfect[i] * perfect[i] = perfect[i+1] for all 1 ≤ i < n.
Here perfect[i] is the size of the set and perfect[i] is the number of rice grains
in bag i.
Find the largest possible set perfect and return an integer, the size of that set. If no such set
is possible, then return -1. It is guaranteed that all elements in riceBags are distinct.
Complete the function maxSetSize in the editor.
maxSetSize has the following parameter:
int riceBags[n]: the list of bags of rice by rice grain counts
Returns
int: the size of the largest set possible or -1 if there is none
ᯓ★ ꒰ა Credit to Nick ໒꒱ ᯓᡣ𐭩
1Example 1
2Example 2

Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 2 × 105
2 ≤ riceBags[i] ≤ 106