TORONTO KIDS COMPUTER CLUB | Friday 17:00 Python Practice 21.04.09.
post-template-default,single,single-post,postid-19278,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Friday 17:00 Python Practice 21.04.09.

14 Apr Friday 17:00 Python Practice 21.04.09.

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
5 2 3 7 9 8 11
0 6
1 5
2 6
3 4

Sample Output

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.

No Comments

Sorry, the comment form is closed at this time.