Problem Β· Array
Find Largest Set of Onion Bags π
Learn this problemProblem statement
You are shopping online for some bags of onion. Each listing displays the number of onions that the bag contains. You want to buy a perfect set of onion bags from the entire search results list, onionBags. A perfect set of onion bags, perfect, is defined as:
perfect are sorted in increasing order by count, it satisfies the condition perfect[i] = perfect[i+1] for all 1 β€ i < n. Here n is the size of the set and perfect[i] is the number of onion 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 onionBags are distinct.
Function
findLargestSet(onionBags: int[]) β intExamples
Example 1
onionBags = [3, 9, 4, 2, 16]return = 3The following are the perfect sets:
Set
Set
Set
Set
The size of the largest set is 3. The image below illustrates the correct ordering of the purchased onion bags by count.
perfect = [3, 91]. The size of this set is 2.perfect = [4, 2]. The size of this set is 2.perfect = [4, 16]. The size of this set is 2.perfect = [4, 2, 16]. The size of this set is 3.Constraints
Unknown for nowMore Amazon problems
- Secure Maximum DeliveriesOA Β· Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW Β· Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN Β· Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN Β· Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW Β· Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW Β· Seen Jul 2026
- Maximum System Memory CapacityOA Β· Seen Jul 2026
- Package Delivery SystemOA Β· Seen Jul 2026