AMAZON_HACKON Coding Question – Solved

4 Live
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]

Asked in: AMAZON_HACKON

Image of the Question

Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |