Smallest Pair
Practice this coding question on Coding Gurukul.
Problem statement
A student team must buy two components from a list of available offers. Every offer represents a separate physical component, and the team needs two different components. Their only objective is to minimise the combined price; compatibility and delivery time are already handled elsewhere. Several independent shopping lists are provided for comparison. Your task For each test case, choose two different array positions and print the smallest possible sum of their values. Equal prices at different positions may both be chosen. You are asked for the sum, not the selected indices or the two prices separately. Important details The array always contains at least two entries. You cannot use the same physical component twice, even if its price is the lowest. Distinct positions do not require distinct numeric values. Worked example For prices [8,3,3,9], the two components priced 3 are different offers. Choosing both gives the minimum total 6.
Input format
First line: T. For each test case: n, followed by n prices.
Output format
Print the minimum pair sum for each test case.
Constraints
1 <= T <= 100; 2 <= n <= 100000; 0 <= price <= 1000000000; total n <= 200000.
Sample input
1 4 8 3 3 9
Sample output
6
Sign in to run or submit a solution in C++, Java or Python.