class Solution { 2. at is the smallest possible ampitude of array A that can achieve by performing at most three moves? The olitude of an array is the difference between the est and the smallest values it contains publie statie lat solution(int[] A) ( Systen.err.printin("Tip: Use Systen.err.prim return e te a function: ss Solution (public int solutionint AL) t given an array A of N integers, retuns the smallest aplitude that can be obtained after replacing up to ee elements of array A

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
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
Transcribed Image 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
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY