Last Updated: 29 Sep, 2025

Equal Cost Packages

Moderate
Asked in company
Amazon

Problem statement

In an online marketplace, you are tasked with creating product packages. You are given an array of integers, itemCosts, representing the cost of each available item.


Your goal is to form the maximum possible number of packages, subject to two rules:


1) Each package can contain at most two items.


2) All packages formed must have the same total cost.


Each item can be used in at most one package. Determine the maximum number of packages you can create.


Input Format:
The first line of input contains an integer 'N', the number of items.

The second line contains 'N' space-separated integers, representing the itemCosts array.


Output Format:
Print a single integer representing the maximum number of packages that can be formed.


Note:
The main challenge is that the target cost for the packages is not given. You must determine the optimal target cost yourself.

The target cost for a package must be a sum that can be formed by either one or two items from the list.