Question: code javascript: Compute how many types of items can stay in a storeroom after removing R consecutive items. Task description A storeroom is used to
code javascript: Compute how many types of items can stay in a storeroom after removing R consecutive items.
Task description
A storeroom is used to organize items stored in it on N shelves. Shelves are numbered from to N The Kth shelf is dedicated to items of only one type, denoted by a positive integer AK
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:
function solutionA 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:
Given A and R your function should return It can be achieved, for example, by freeing shelves and shelves are numbered from
Given A and R your function should return All three types can still be stored by freeing the last two shelves.
Given A and R your function should return It can be achieved by freeing the first three shelves.
Given A and R your function should return All shelves need to be freed.
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
R is an integer within the range N;
each element of array A is an integer within the range
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
