Java We are given an array A consisting of N integers. In one move, we can choose any element in this array and replace it with any value. Keyboard navigation: Use Tab to advance the cursor. To exit...


Java<br>We are given an array A consisting of N integers. In one<br>move, we can choose any element in this array and<br>replace it with any value.<br>Keyboard navigation: Use Tab to advance the cursor. To exit the editor, press the ctrl and<br>keys<br>What is the smallest possible armpltude of array A that<br>we can achieve by performing at most three moves? The<br>amplitude of an array is the difference between the<br>largest and the smallest values it contains<br>class Solution {<br>2.<br>publie statie tnt solution(int[) A) (<br>14<br>Systen, err.println(

Extracted text: Java We are given an array A consisting of N integers. In one move, we can choose any element in this array and replace it with any value. Keyboard navigation: Use Tab to advance the cursor. To exit the editor, press the ctrl and keys What is the smallest possible armpltude of array A that we can achieve by performing at most three moves? The amplitude of an array is the difference between the largest and the smallest values it contains class Solution { 2. publie statie tnt solution(int[) A) ( 14 Systen, err.println("Tipr Use System.ere.printin() to write debug nessages on the output tab. ") Ireturn e 7. Write a function: class Solution (public int solutioniint A ) that, given an array A of N integers, returns the smallest amplitude that can be obtained after replacing up to three elements of array A Examples: 1. Given A19, 8-11, the function should return 0 We can replace 9 and 8 with-1 so that all elements are equal to-1, and then the amplitude 2. Given A (14, 10, 5, 1, 0L the function should retum 1. To achieve an amplitude of 1, we can replace 14, 10 and 5 with 1 or 0. 3. Given A 11, 04,-1,-3, the function should return 3. This can be achieved, for example, by replacing 11,-6 and 5 with three valuee of 2. 4. Given A10, 10, 4,210L the function should return 0. We can replace 2 and a with 10, making the amplitude equal to D S. Given A R-1, 4,3,511 the function should return 2. Replacing and both ocurrences of 1 with for example, 34 and 5 results in an ampitude equal to 2 Assume that Nan integer withi the range 12.121 each element of aay A is an integer within the range1-0.sa. an In your solution, focus on correctness The performance of your eolution will not be the focus of the assesumeit ef and
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here