Dsa
Greedy
Hard
Minimum Cost to Assemble Toys
You are tasked with assembling toys from various parts. Each toy requires exactly two parts, and each part has a cost associated with it. Your goal is to assemble as many toys as possible while minimizing the total cost. Given a list of costs for the parts, determine the minimum total cost to assemble the maximum number of toys.
Input Format:
- The first line contains an integer N (1 <= N <= 1000), the number of parts.
- The second line contains N integers, each representing the cost of a part (0 <= cost <= 1000).
Output Format:
- Print a single integer, the minimum cost to assemble the maximum number of toys.
Example:
Input:
6
1 2 3 4 5 6
Output:
9
In this example, there are 6 parts with costs 1, 2, 3, 4, 5, and 6. You can pair parts (1,2), (3,4), and (5,6) to minimize the cost, resulting in a total minimum cost of 9.
Key concepts
greedyarrayssorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now