AMAZON_HACKON Coding Question β Solved
Prince was playing games on his computer all day, so his father decided to give him the task of arranging the books kept on the bookshelf. Prince can arrange the books on the bookshelf according to the book type, where an English alphabet denotes each book type. He is required to arrange the books in such a way that the book type having the lowest number of copies is kept first, and the book type having the maximum number of copies is kept last. If two or more book types have the same number of books, arrange them in lexicographically ascending order.
You are given two numbers, L and R. Return the total number of books of type A E I O U between [L, R], which are present on the bookshelf.
Input Format: The first line contains an integer n denoting the number of books. The second line contains n space-separated uppercase English alphabets that denote the type of book. The third line contains two space-separated integers denoting L and R.
Output Format: Return the total number of books of type A E I O U between [L, R] on the bookshelf.
Constraints: 1 <= N <= 100. The book type is uppercase English alphabet only.
Sample Testcase 1
Input:
7
BBAABCC
1 2
Output:
2
Explanation: In this case, 2 books are of type A, 2 books are of type C, and 3 books are of type B. Hence, after arranging them according to the given condition, the shelf looks like this: AACCBBB (let's say string y). Here, the frequency of A and C are the same, so they are sorted in lexicographically ascending order. The distinct types of book that is kept on the shelf after arrangement is ACB (let's say string x). The value of L=1 and R=2. Therefore, the number of books of type A E I O U in the range [1,2] in string x is 1, i.e., the type A. The number of books of type A in string y is 2; hence, the answer is 2.
Sample Testcase 2
Input:
7
CABCABB
1 3
Output:
[Output not provided]