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...
-
Assume that on January 2, 2010, Maxwell of Michigan purchased fixtures for $8,800 cash, expecting the fixtures to remain in service for five years. Maxwell has depreciated the fixtures on a...
-
A pipeline transporting crude oil (sg = 0.93) at 1200 L/min is made of DN 150 Schedule 80 steel pipe. Pumping stations are spaced 3.2 km apart. If the oil is at 10C, calculate (a) The pressure drop...
-
How can a plaintiff enforce a settlement agreement made by the defendant?
-
On January 1, 2016, Prairie Enterprises purchased a parcel of land for $28,000 cash. At the time of purchase, the company planned to use the land for a warehouse site. In 2018, Prairie Enterprises...
-
In Year 1, Victoria Textiles Limited decided that its Asian operations had expanded such that an Asian office should be established. The office would be involved in selling Victoria's current product...
-
Portfolio return and standard deviation David Choo is thinking of building an investment portfolio containing two stocksH and G. He has assigned 40% of his portfolio to stock H and the remaining 60%...
-
Balancing work quality with timeliness can be a challenging task for any project manager. Discuss two strategies or resources project managers can use to assist with this task. provide examples of...
-
A heterozygous person carrying both the dominant normal hemoglobin allele and the recessive sickle cell hemoglobin allele has a fitness advantage over homozygous dominant individuals with respect to...
-
Some financial institutions pay daily interest, compounded by the 360/365 method, using the following formula. r 365t A = A (1 1 + 360 (t is in years) Using this method, what will an initial...
-
Information concerning Maida Maids Company's manufacturing activities for December follows: Finished goods Direct materials Direct labor Machine time Work in process Direct materials, P2.40 per unit...
-
A corporation has 10,000 bonds outstanding with a 6% semi-annual coupon rate, 10 years to maturity, a $1,000 face value, and a $1,100 market price. The company's 100,000 shares of preferred stock pay...
-
Simplify: x8y3/8 x3y1/2x7 1
-
Consider a car moving along a straight line with direction r ER at constant (nonzero) speed on the plane. Let x (t) and x (t) denote the horizontal and vertical position of the center of mass of the...
-
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.
-
Trudeau's net cash flow from financing activities for 2020 was a. net cash used of \(\$ 25,000\). b. net cash used of \(\$ 20,000\). c. net cash provided of \(\$ 10,000\). d. net cash used of \(\$...
-
Sales totalled \(\$ 800,000\), accounts receivable increased by \(\$ 40,000\), and accounts payable decreased by \(\$ 35,000\). How much cash did this company collect from customers? a. \(\$...
-
Income Tax Payable was \(\$ 5,000\) at the end of the year and \(\$ 2,800\) at the beginning. Income tax expense for the year totalled \(\$ 59,100\). What amount of cash did this company pay for...
Study smarter with the SolutionInn App