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...
-
Consider a normal distribution with mean 5 and standard deviation 2. a. Sketch the associated normal curve. b. Use the footnote on page 244 to write the equation of the associated normal curve. c....
-
Consider the steps of the accounting cycle (recording of transactional and adjusting journal entries, posting of entries, preparation of the trial balance, and recording and posting of closing...
-
You are considering accepting a job at Big Business Corporation. As a condition of employment, you must sign a covenant not to compete with Big Business in which you agree that when your employment...
-
The Bawl Corporation supplies alloy ball bearings to auto manufacturers In Detroit. Because of its specialized manufacturing process, considerable work-in -process and raw materials are needed. The...
-
16. A uniform solid right circular cone of base radius R is joined to a uniform solid hemisphere of radius R and of the same density, so as to have a common face. The centre of mass of the composite...
-
On January 1, 2015, 100% of the outstanding stock of Solo Company was purchased by Plato Corporation for $3,300,000. At that time, the book value of Solo's net assets equaled $3,000,000. The excess...
-
Given the sets X,Y, 2, and U, find the set Xn(x-y) using the listing method. x= {bedf} Y= { bce} 2= {cegid,a} U= {a,b,cid, e, fq} |xn(x-Y)= {0} (use a comma to seperate answers as needed
-
The stock market is highly volatile. What accounts for this?
-
How can structured securities create value?
-
What is a securitys beta? Does a high beta make a security attractive or unattractive for a portfolio? A low (or negative) beta? Why or why not?
-
What is meant by asset-backed commercial paper? SPVs? How have large commercial and investment banks used ABCP to reduce the amount of capital they need?
-
How do pools of nonconforming mortgages differ from those of Ginnie, Fannie, and Freddie? In forming these pools, what do issuers have to do to make them attractive to investors?
-
1. Kate Kramer is the owner and operator of The Kramer Company located in Kingston, Ontario. On September 30, 20-, The Kramer Company had the following assets and liabilities. A. Prepare the...
-
On the basis of the details of the following fixed asset account, indicate the items to be reported on the statement of cashflows: ACCOUNT Land ACCOUNT NO. Balance Date Item Debit Credit Debit Credit...
-
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...
-
Islands tend to have fewer species than the mainlands they resemble. Furthermore, island species often include many flying organisms and few terrestrial ones. Do these biogeographic patterns support...
-
Laura says she doesnt believe that humans were at one time chimpanzees or gorillas. Jeff says he doesnt believe it either. Explain why biologists also dont believe that humans are descended from...
-
Write a letter to Grandma telling her about drug resistance in living organisms. Explain to her why drug resistance is such a common phenomenonincluding why insects become more resistant to...
Study smarter with the SolutionInn App