Problem Statement | |||||||||||||
We have an array of positive integers. We will transform this array by repeating the following operation until there are less than two elements left:
For example, suppose we have an array of four integers {3, 2, 3, 2}. The transformation process goes like this: Step 1: (3, 2, 3, 2) --> (3, 1, 3, 1) (decreasing values 2 and 2) Step 2: (3, 1, 3, 1) --> (3, 3) (decreased elements became zeros, so we removed them) Step 3: (3, 3) --> (2, 2) Step 4: (2, 2) --> (1, 1) Step 5: (1, 1) --> () Thus, we have an empty array at the end of the process. You are given a int[] elements which represents the array to transform. Return the number of steps in the transformation process. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
| - | elements will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each element of elements will be between 1 and 1000, inclusive. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||