Problem Statement
You are given an int[] A of positive integers. In a single turn, you can do the following: Choose any value X that is greater than 1. Let C be the number of occurrences of X in the array A. You then subtract 1 from exactly C/2 (rounded down) of those occurrences.
Find the lexicographically smallest array you can obtain after performing any number of turns.
Definition
- Class:
- ValueDivision
- Method:
- getArray
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] getArray(int[] A)
- (be sure your method is public)
Constraints
- A will contain between 1 and 1,000 elements, inclusive.
- Each element of A will be between 1 and 109, inclusive.
Examples
{1, 5, 7, 4, 5, 4, 1}Returns: {1, 2, 7, 3, 5, 4, 1 }{7}Returns: {7 }{7, 4}Returns: {7, 4 }{7, 7, 7, 7}Returns: {4, 5, 6, 7 }