Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you solve this in Java 8? 2. Frequency of Maximum Value For a given array of integers, determine the maximum value in the segment

Can you solve this in Java 8? image
image

2. Frequency of Maximum Value For a given array of integers, determine the maximum value in the segment from each index to the highest index element, inclusive. After that has been determined, determine the number of times that highest value occurs in the segment. A number of queries will then be given, where each query represents an index within the array. Create a return array with one value for each query: the number of times the maximum value occurs in a segment starting at that index. Example numbers = [5, 4, 5, 3, 21 9=[1,2,3,4,5] Note: The numbers array indexes are from 1 to n where n is the length of the array. For the first query, the index is 1. The segment starting at index 1 is [5, 4, 5, 3, 2]. The highest value is 5, and it occurs 2 times. result = [2] For the second query, the index is 2. The segment starting at index 2 is (4, 5, 3, 2]. The highest value is 5, and it occurs 1 time. result=[2.1] In each of the remaining segments queried, [5, 3, 21, [3, 2], and [2], there is only one occurrence of a highest value so a 1 is appended to result for each query. The final array returned is [2, 1, 1, 1, 1]. Function Description Complete the frequencyOfMaxValue function in the editor below. The function must return an integer array that denotes the answers to the query array. frequencyOfMaxValue has two parameters: int[n] numbers: an integer array that contains the values of the n items available in the shop int[m] q: an integer array that contains the index values for each query Returns: int[m]: an integer array with the answers to each query, aligned by index Constraints MacBook Air import java.io.*; class Result { } Complete the frequencyOfMaxValue function below. The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. INTEGER ARRAY numbers * 2. INTEGER ARRAY q Autocomplete Ready O public static List frequencyOfMaxValue(List numbers, List g) { // Write your code here } public class Solution {-

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

Java program to create a static method that returns a list of integers c... 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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Electrical Engineering questions