10611 - The Playboy Chimp


Difficulty : easy

Solution Description :

Searching  Problem

4
1 4 5 7 // the height always increasing order

query
4
4 6 8 1

For 4: nearest left value 1, and nearest right value 5. Output: 1 5
For 6: nearest left value 5, and nearest right value 7. Output: 5 7
For 8: nearest left value 7, and have not nearest right value. Output: 7 X
For 1: have not nearest left value, and nearest right value 4. Output: X 4

You can find the nearest left value and nearest right value using binary search.
Or you can use c++ stl lower_bound() and upper_bound() method.