14 Apr Aurora Saturday 14:30 Python Practice 21.04.10.
Question 1:
Apple has come to hire interns from your classmates. N students got shortlisted out of which few were males and a few females. All the students have been assigned talent levels. Smaller the talent level, lesser is your chance to be selected. Apple wants to create the result list where it wants the candidates sorted according to their talent levels, but there is a catch. This time Apple wants to hire female candidates first and then male candidates.
the task is to create a list where first all female candidates are sorted in a descending order and then male candidates are sorted in a descending order.
Input Specification:
The first line contains an integer N denoting the number of students. Next, N lines contain two space-separated integers, ai and bi.
The first integer, ai will be either 1(for a male candidate) or 0(for female candidate).
The second integer, bi will be the candidate’s talent level.
Output Specification:
Output space-separated integers, which first contains the talent levels of all female candidates sorted in descending order and then the talent levels of male candidates in descending order.
Sample Input 5 0 3 1 6 0 2 0 7 1 15 Sample Output 7 3 2 15 6
Question 2:
Mr. Ken is upset because of his short height. Now, he wants to imagine himself taller. So he decided to stand in front of K pillars of different heights i.e. the jth pillar has height hi. Now to feel taller, he wanted to know how many buildings he is able to see within the range [l,r] both inclusive?
Input Specification:
The first line contains an integer K denoting the number of pillars.
The next line contains K integers denoting the height of jth pillar.
The next line contains a single integer Q (number of queries).
Next, Q lines contain pairs l and r respectively.
Output Specification
For every Q queries print the number of buildings visible in the range [l, r].
Sample Input 7 5 2 3 7 9 8 11 4 0 6 1 5 2 6 3 4 Sample Output 4 4 4 2 Explanation In query 1- 5, 7, 9, 11 pillars are visible so the answer is 4. In query 2 -2, 3, 7, 9 are visible so the answer is 4.
Sorry, the comment form is closed at this time.