Write a Java function that will process a large array of numbers. It takes an int array…
- User
Write a Java function that will process a large array of numbers. It takes an int array as the only parameter. The input array will be big (over one million ints), so pay attention to efficiency. The most of the numbers will range from -100 to 100, but once in a while they will be bigger. The function, processInputIntegers, should return a list of numbers that is constructed according to the following instructions:
Process the values in the input array sequentially. If the value is negative, add it to the list that you will return. If the value is positive, do not add it. Instead, remove the n-th element in the list to be returned, where n = value. For example, if the value is 2, remove the 2nd element. If the removal would cause an ArrayIndexOutOfBoundsException, do nothing and a disaster avoided code comment. Also do nothing when the value is zero. The ratio of positive to negative ints will be roughly equal.
Example: for the input [-1, -2, -3, 2] the result is [-1, -3].
- Assistant