In Amazon's online marketplace, the inventory manager is exploring strategies to enhance product sales. The focus is on creating appealing packages that offer customers a delightful shopping experience. To achieve this, the inventory manager aims to construct packages, each containing at most 2 items, to have an equal total cost across all packages. The total cost of a package is defined as the sum of the costs of the items contained within.
Formally, given an array cost of size n, representing the costs of individual items, determine the maximum number of packages that can be created, such that each package adheres to the constraint of having at most 2 items, and all packages have the same cost.
Note that each item can be used in at most one package.
Complete the function findMaximumPackages in the editor.
findMaximumPackages has the following parameter:
int cost[n]: an array of integers denoting the cost of each item in the shop.
Returns
int: the maximum number of packages that can be made having the same cost, where each package consists of at most 2 items.
ᨒ ོ ☼ As always, manyyy thanks to spike and aikay!!
cost = [4, 5, 10, 3, 1, 2, 2, 2, 3] return = 4

cost = [1, 1, 2, 2, 1, 4] return = 3

cost = [2, 1, 3] return = 2

cost = [4, 5, 10, 3, 1, 2, 2, 2, 3] return = 4

cost = [10, 2, 1] return = 1
1 ≤ n ≤ 2 * 10^51 ≤ cost[i] ≤ 2000
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int findMaximumPackages(int[] cost) {
// write your code here
}