Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to implement the method longestPlateau(). Plateau: the values of the elements just before and just after a sequence of elements are

image text in transcribed

Write a Java program to implement the method longestPlateau().

Plateau: the values of the elements just before and just after a sequence of elements are either smaller or non existent.

For example, on the input array [2, 3, 3, 3, 3, 6, 6, 1, 1, 1], it returns [6, 5, 2], * indicating the longest plateau of this array is the subarray [6, 6]; it starts at * index 5 and has length 2.

For example, on the input array [3, 3, 1, 2, 4, 0, 1, 1, 1, 1], it returns [1, 6, 4]

For example, on the input array [3, 3, 1, 2, 4, 2, 1, 1, 1, 1], it returns [3 , 0 , 2]

Lolors Consider a non-empty int array ints. A contiguous subarray ints start.. start + len -1 ] (with starting index start and length len) is called a flat if all elements of that subarray are equal. Furthermore, such a subarray is called a plateau if it is flat and each of the elements ints(start-1] and ints(start + len) that immediately proceed/succeed the subarray are either nonexistent i.e., out of array's index range) or are strictly smaller than the elements of the subarray. Your task includes the design of a public static method longest Plateau(int[] ints) that returns (a compact description of) the longest plateau of the input array ints. You may break ties arbitrarily if ints has more than one longest plateau. The return type should be a 3-element array representing (value, start, len}: The first indicates common element value ints(start of the plateau, the second its starting index, the third its length. Implement the longest Plateau() method in the provided ArrayLongest Plateau class so that it performs as indicated. The main() method in this class runs some test cases on longest Plateau(). You should also add a few nontrivial and interesting test cases of your own at the end of main(). Longestplateau) returns the longest plateau of an array of ints. * @return an array int13] of the form {value, start, len} representing the longest plateau of int[] as a length len contiguous subarray starting at index start with common element values value. For example, on the input array (2, 3, 3, 3, 3, 6, 6, 1, 1, 1], it returns [6, 5, 2), indicating the longest plateau of this array is the subarray [6, 6]; it starts at index 5 and has length 2 For example, on the input array [3, 3, 1, 2, 4, 0, 1, 1, 1, 1 1, it returns (1, 6, 4) Write a Java Code to implement the method longest.Plateau Please explain your solution and make sure that they pass the case or the two examples above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Is it clear what happens if an employee violates the policy?

Answered: 1 week ago