Company: Visa (Associate SW Engineer)
Difficulty: medium
You are given an array skill of even length, where each element represents a participant's skill value. Your task is to form teams of exactly two participants such that: Every participant is used exactly once All teams have the same total skill (i.e., for every pair [a, b], a + b is the same) The efficiency of a team [a, b] is defined as: efficiency = a * b You must: Form valid teams (if possible) Compute the sum of efficiencies of all teams If it is not possible to form teams where all pairs have the same skill sum, return -1 It is guaranteed that if a valid arrangement exists, the result is unique. Example 1 Suppose the skills of the candidates are skill = [1, 2, 3, 2] . Output: 7 Explanation: They can be paired as [[1, 3], [2, 2]]. The sum of skills for each team is the same, i.e., 4. The efficiency is computed as: Efficiency of [1, 3] = 1 * 3 = 3 Efficiency of [2, 2] = 2 * 2 = 4 The sum of efficiencies is 3 + 4 = 7. Example 2 Suppose the skills of the candidates are skill = [2, 1,