Can you solve this in Java 8? 2. Frequency of Maximum Value For a given array of
Fantastic news! We've Found the answer you've been seeking!
Question:
Can you solve this in Java 8?
Transcribed Image Text:
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 {- 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 {-
Expert Answer:
Answer rating: 100% (QA)
Java program to create a static method that returns a list of integers c... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these electrical engineering questions
-
This question requires you to solve a supply-and-demand model algebraically. Letting p be the price of the product, suppose the demand and supply functions for some product are given by QD= 100 - 3p...
-
This assignment will help you get acquainted with your Java development software. Here is the Java program you will enter: // This is my first Java program. public class MyFirstProgram { public...
-
In order to solve this problem, you must read the description of the Hammett Ï, Ï treatment given in Chapter 17, Problem 76. When the rate constants for the hydrolysis of several morpholine...
-
The following appliances are connected to a single 120 V, 15 A circuit in a kitchen: a 330 W blender, a 1000 W coffeepot, a 150 W coffee grinder, and a 750 W microwave oven. If these are all turned...
-
In its automated processing system over payroll transactions, Brady Company enters the following data from its employees attendance records (# corresponds to a numeric field; A corresponds to an...
-
Garfield Company purchased, as a held-to-maturity investment, $80,000 of the 9%, 5-year bonds of Chester Corporation for $74,086, which provides an 11% return. Prepare Garfields journal entries for...
-
The following scenarios describe situations faced by hypothetical companies that currently have a centralized organization structure. As you review each of the scenarios, provide your opinion as to...
-
Protrade Corporation acquired 80 percent of the outstanding voting stock of Seacraft Company on January 1, 2014, for $612,000 in cash and other consideration. At the acquisition date, Protrade...
-
The local theater company is choosing its next play. The company's members recently held a vote to decide which of three choices - Elektra, Tartuffe, and Hamlet - the company will perform. The...
-
3. Write a memo Shelby Cobb and Alexis Hinojosa, the two supervisors to whom you report, have asked you to compose a draft memorandum for their joint signatures. Recently there has been a flurry of...
-
You are the Controller of a company that has recently been acquired by a larger organization. You and your team have been asked to provide a summary of the financial performance of your organization...
-
Suppose a ten-year, $3,000 bond with an 8.6% coupon rate and semiannual coupons is trading for $1,034.91. a. What is the bond's yield to maturity (expressed as an APR with semiannual compounding)? b....
-
A person (mass 40.0kg) is coasting on their skateboard (mass 4.50kg) at 8.00m/s. They suddenly jump directly backward off the skateboard, kicking the skateboard forward at 10.0m/s. As soon as their...
-
Based on the cash flows given below, calculate the PI of a project that has a required rate of return of 15 percent. Also, indicate whether the project should be accepted. (Round answer to 2 decimal...
-
Use the Seaport data set below to calculate a 3-month Weighted Moving Average (WMA) to predict the number of ships that will visit the port in January 2021. Use the weights of 0.5, 0.4, and 0.1 for...
-
The IRS suspended the casualty and theft loss deductions for all taxpayers, except those in a federally declared disaster area. What is California's position on this?
-
Suppose that today you buy an 7% annual coupon bond for $870. The bond has 10 years to maturity. Three years later, the YTM on your bond has increased by 1% andyou decide to sell. Required: a. What...
-
What recommendations would you make to Big Four firms to help them (1) avoid confrontations with governmental officials in an authoritarian society and (2) deal effectively with such confrontations...
-
Show that there are at most n=2 h + 1 nodes of height h in any n-element heap.
-
Let X be a random variable that is equal to the number of heads in two flips of a fair coin. What is E [X 2 ]? What is E 2 [X]?
-
For the set of {1, 4, 5, 10, 16, 17, 21} of keys, draw binary search trees of heights 2, 3, 4, 5, and 6.
-
The codon change (Gly-12 to Val-12) in human H-ras that converts it to oncogenic H-ras has been associated with many types of cancers. For this reason, researchers would like to develop drugs to...
-
Outline the general strategy used in metagenomics.
-
You need to understand the approach described in question 3 in More Genetic TIPS before answering this question. A muscle-specific gene was cloned and then subjected to promoter bashing. As shown...
Study smarter with the SolutionInn App