132 Geeky Buildings
Hard Accuracy: 49.05% Submissions: 10540 Points: 8

There are N buildings in Linear Land. They appear in a linear line one after the other and their heights are given in the array arr[]. Geek wants to select three buildings in Linear Land and remodel them as recreational spots. The third of the selected building must be taller than the first and shorter than the second.
Can geek build the three-building recreational zone? 

Example 1:

N = 6
arr[] = {4, 7, 11, 5, 13, 2}
[4, 7, 5] fits the condition. 

Example 2:

N = 4
arr[] = {11, 11, 12, 9}
No 3 buildings fit the given condition. 

Your Task:
You don't need to read input or print anything. Complete the function recreationalSpot() which takes the array arr[] and its size N as input parameters and returns a boolean value based on whether his building selection was successful or not.
Note: The generated output will be "True" or "False".

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

1 ≤ N ≤ 104
1 ≤ arr[i] ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

132 Geeky Buildings

Output Window