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...
-
The collection of emerald diamonds contains replications, several diamonds at each weight. Had we fit the linear equation using average price at each weight rather than individual diamonds, how would...
-
The H & L Bark Company is considering the purchase of a debarking machine that is expected to provide cash flows as follows: If the appropriate annual discount rate is 14 percent, what is the present...
-
Organizations have traditionally used employee time saved as the primary source of benefits to justify HRIS and other types of information system investments. Why can this be problematic? Give...
-
Selected data concerning the past years operations of the Lone Star Leather Company are as follows: Required: 1. What was the cost of raw materials purchased during the year? 2. What was the...
-
Product costs using activity rates Friedman.com Inc. sells consumer electronics over the Internet. For the next period, the budgeted cost of the sales order processing activity is $145,000, and...
-
2. Firm ABC has based on nominal interest rate to compute and pay the interest payment because of its debt amount. Moreover, the firm has purchased an asset and use the Double Declining Balance Model...
-
Define the following terms: Established Cell Line: Cell Strain: Histotypic Culture: Explant: Clone:
-
Three parallel-plate capacitors are separately connected to identical batteries. Capacitor 1 has a plate area \(A\) and a plate separation \(d\). Capacitor 2 has a plate area \(2 A\) and a plate...
-
Graph the lines through the given points and with the given slopes as indicated in Problems 19-30. \((2,3) ; m=0\)
-
Graph the lines through the given points and with the given slopes as indicated in Problems 19-30. \((6,3) ; m=-\frac{2}{5}\)
-
Graph the lines through the given points and with the given slopes as indicated in Problems 19-30. \((2,-3) ; m=1.5\)
-
The market price of the stock of the Bernstein Corporation is \(\$ 50\) per share and there are one million shares outstanding. Suppose that the management of this corporation is considering a rights...
-
Identify the formal structure of Snapple company. How is Snapple company structure and design a reflection of its environment, goals, and competencies?
-
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...
-
Under an evolutionary classification system, species are grouped together based on (a) their shared similarities. (b) how closely related they are to one another. (c) their position in a hierarchy...
-
What criteria are used to classify species in the Linnaean system?
-
What criteria are used to classify species in an evolutionary classification system?
Study smarter with the SolutionInn App