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...
-
Given the recent experience of the International Monetary Fund (IMF), what is now the primary function of this organization?
-
Listed here are the stockholders equity sections of three public companies for 2017 and 2018. Required a. Divide the class in three sections and divide each section into groups of three to five...
-
27. Cammie received 100 NQOs (each option provides a right to purchase 10 shares of MNL stock for $10 per share) at the time she started working for MNL Corporation (5/1/Y1) four years ago when MNLs...
-
One of the major controversies in project management occurs over whether the project manager needs a command of technology in order to be effective. Consider the following situation: You are the...
-
You purchase a convertible at $110. It has an investment value of $75 and a conversion value of $100. Assuming the credit risk does not change, what is the value of the convertible if the stock price...
-
Create Strategic Asset Allocation for the hypothetical investor Your first client is Jim and Karla Sanders who are 25 and 22, respectively. Jim and Karla have been married for two years and have a...
-
A recent study 1 examined the relationship between football playing and hippocampal volume, in L, in the brain. We use the n=25 participants in the control group to estimate average brain hippocampus...
-
Molina Company produces three products: A130, B324, and C587 All three products use the same direct material, Brac Unt data for the three products are in the provided table. (Click to view the unit...
-
MFGE 437 S21 - Homework 1 Submissions will be Online! Please scan your HWs and upload on Canvas Problem 1: A vertical milling machine is to be retrofitted with three identical DC servo motors. The...
-
On January 1, Palisades, Inc., acquired 100 percent of Sherwood Company's common stock for a fair value of $120,340,000 in cash and stock. The carrying amounts of Sherwood's assets and liabilities...
-
(1) A test balloon has an accelerometer attached to it. After you release it and start collecting data it is 5 ft in front of you and 16 ft above you, and it is moving 5 ft/s to your left and 4 ft/s...
-
484 ... Age of Accounts as of June 30, 2019 1-30 31-60 61-90 Over 90 Customer Name Days Days Days Days Total Balance Canyon Youth Club $ 250 $ 250 Crazy Tees 200 $ 150 350 Early Start Daycare $500...
-
According to AASB 16, lessees always have to recognise a lease on their balance sheets whereas lessors can classify a lease as either a finance lease or an operating lease. TrueFalse For lessees, one...
-
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...
-
Explain the difference between expenses and expenditures in a state and a local government. AppendixLO1
-
Explain the necessity to introduce a deferred revenues account in the levy of capital special assessments. AppendixLO1
-
The debt service fund does not use budgetary accounts. What is the logic for not doing so? AppendixLO1
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App