A storeroom is used to organize items stored in it on N shelves. Shelves are numbered...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A storeroom is used to organize items stored in it on N shelves. Shelves are numbered from 0 to N-1. The K-th shelf is dedicated to items of only one type, denoted by a positive integer A[K]. Recently it was decided that it is necessary to free R consecutive shelves. Shelves cannot be reordered. What is the maximum number of types of items which still can be stored in the storeroom after freeing R consecutive shelves? Write a function: int solution (vector<int> &A, int R); that, given an array A of N integers representing types of items stored on storeroom shelves, and an integer R representing the number of consecutive shelves to be freed, returns the maximum number of different types of items that can be stored in the storeroom after freeing R consecutive shelves. Examples: 1. Given A = [2, 1, 2, 3, 2, 2] and R = 3, your function should return 2. It can be achieved, for example, by freeing shelves 2, 3 and 4 (shelves are numbered from 0). %3D %3D 2. Given A = [2, 3, 1, 1, 2] and R = 2, your function should return 3. All three types can still be stored by freeing the last two shelves. %3D 3. Given A = [20, 10, 10, 10, 30, 20] and R = 3, your function should return %3D 3. It can be achieved by freeing the first three shelves. 4. Given A = [1, 100000, 1] and R = 3, your function should return 0. All %3D shelves need to be freed. Write an efficient algorithm for the following assumptions: N is an integer within the range [1..100,000]; Ris an integer within the range [1..N]; each element of array A is an integer within the range [1..100,000]. A storeroom is used to organize items stored in it on N shelves. Shelves are numbered from 0 to N-1. The K-th shelf is dedicated to items of only one type, denoted by a positive integer A[K]. Recently it was decided that it is necessary to free R consecutive shelves. Shelves cannot be reordered. What is the maximum number of types of items which still can be stored in the storeroom after freeing R consecutive shelves? Write a function: int solution (vector<int> &A, int R); that, given an array A of N integers representing types of items stored on storeroom shelves, and an integer R representing the number of consecutive shelves to be freed, returns the maximum number of different types of items that can be stored in the storeroom after freeing R consecutive shelves. Examples: 1. Given A = [2, 1, 2, 3, 2, 2] and R = 3, your function should return 2. It can be achieved, for example, by freeing shelves 2, 3 and 4 (shelves are numbered from 0). %3D %3D 2. Given A = [2, 3, 1, 1, 2] and R = 2, your function should return 3. All three types can still be stored by freeing the last two shelves. %3D 3. Given A = [20, 10, 10, 10, 30, 20] and R = 3, your function should return %3D 3. It can be achieved by freeing the first three shelves. 4. Given A = [1, 100000, 1] and R = 3, your function should return 0. All %3D shelves need to be freed. Write an efficient algorithm for the following assumptions: N is an integer within the range [1..100,000]; Ris an integer within the range [1..N]; each element of array A is an integer within the range [1..100,000].
Expert Answer:
Answer rating: 100% (QA)
Salution Basically we have to find minimum Confinaus ... View the full answer
Related Book For
Fundamentals of Corporate Finance
ISBN: 978-1118845899
3rd edition
Authors: Robert Parrino, David S. Kidwell, Thomas W. Bates
Posted Date:
Students also viewed these computer engineering questions
-
Given an array A of n integers in the range [0,n 2 1], describe a simple method for sorting A in O(n) time.
-
For which positive integers n is n4 + 4n prime?
-
Given a message and a positive integer k less than 26, encrypt this message using the shift cipher with key k; and given a message encrypted using a shift cipher with key k, decrypt this message.
-
A steel spur pinion has 16 teeth cut on the 20 full-depth system with a module of 8 mm and a face width of 90 mm. The pinion rotates at 150 rev/min and transmits 6 kW to the mating steel gear. What...
-
(a) What rate of return is needed on the $70,000 portfolio to reach their goal of $210,000 (assuming no additional contributions)? Use Appendix A-3 or visit the Garman/Forgue companion website. (b)...
-
For each of the following products and services, indicate whether it is most likely produced in a process operation or in a job order operation. 1. Luxury cars 2. Vanilla ice cream 3. Apple juice 4....
-
The Mann Corporation began operations in 2015.Information relating to the companys purchases of inventory and sales of products for 2015 and 2016 is presented below. Calculate the weighted-average...
-
The cost behavior patterns on page 222 are lettered A through H. The vertical axes of the graphs represent total dollars of expense, and the horizontal axes represent production in units, machine...
-
Calculate the energy released in an arc flash at 480 volts in which the fault current is 8000 amperes and the duration of the fault is 5 cycles on a 60-Hz circuit.
-
Faced with rising pressure for a $15 per hour minimum wage rate, the farming industry is currently exploring the possible use of robotics to replace some farm workers. The Lettuce Bot is one such...
-
If the price in dollars of a stereo system is given by p(q)=(3600)/(q^(2))+1500, where q represents the demand for the product, find the marginal revenue when the demand is 30 .
-
What are the main consolidation approaches?
-
Should public sector organizations work more on the principle of trust?
-
Who are the main internal and external users of CFSs?
-
What roles can a performance auditor adopt and what conflicts can arise between these roles?
-
What are the potential financial costs and risks of adopting 5G too early? What about the risks of adopting it too late?
-
2. Edmonton has 5 networks, and each network subnetting requirements are below and must use the most efficient use of addressing - Name each network appropriately as per your network design 224 hosts...
-
PC Contractors, Inc., was an excavating business in Kansas City, Missouri. Union Bank made loans to PC, subject to a perfected security interest in its equipment and other assets, including...
-
Southwest Airlines has substantial cash reserves and an investment-grade bond rating. How would the trade-off theory predict that managers of Southwest would raise capital and choose the company's...
-
A credit card offers financing at an APR of 18 percent, with monthly compounding on outstanding charges. What is the effective annual rate (EAR)?
-
Terrell Corp. management is considering purchasing a machine that will cost $117,250 and will be depreciated on a straight-line basis over a five-year period. The sales and expenses (excluding...
-
All Canadian corporations must comply with international accounting standards.
-
Most Canadian corporations are listed on the Toronto Stock Exchange.
-
IFRS must be used for the financial statements of every Canadian public corporation.
Study smarter with the SolutionInn App