Looking for a new job opportunity in Banca Mediolanum?
The Challenges In Detail
Number Game
Sam and Alex are playing a made-up game with numbers. The goal of the game is to make the array contain as many distinct elements as possible after performing some number of operations. In a single operation, Sam can choose any 3 elements from the array and remove the maximum and minimum among the three from the array. Determine the maximum number of elements remaining in the array when all of the elements are distinct.
Example
n = 7
number = [1, 2, 4, 3, 2, 4, 3]
The goal is to maximize the number of distinct elements in the final array, so ignore the 1 which is already distinct. Choose the triplet (2, 2, 3), remove the minimum and maximum elements, 2 and 3, then return the remaining 2 to the array. Now, number' = [1, 4, 3, 2, 4]. Choose another triplet, (3, 4, 4), and remove the minimum and maximum values, then return the 4 to the array. Now number'' = [1, 2, 4], and all 3 elements are distinct. The maximum number of distinct elements possible is 3.
Function Description
Complete the function numberGame in the editor below. The function must return an integer that denotes the maximum number of distinct elements remaining in the array.
numberGame has the following parameter(s):
number int[]: an integer array
Constraints
- 3 ≤ n ≤ 105 , and n is odd
- 1 ≤ number[i] ≤ 105
© 2019 | CODEMOTION | VAT IT12392791005 info@codemotionworld.com PRIVACY POLICY. The prizes can under no circumstance be converted into cash. Codemotion reserves the right to change any and all terms of her promotions without prior notification.