please tell me if it is a adhoc based question or we need to know certain things beforehand to solve it?
No special knowledge needed. Just a little use of logic will do
FMg1i4 - Online C++0x Compiler & Debugging Tool - Ideone.com Here is a link to my code…hope it helps
This my O(log(L)) solution. I used Divide and Conquer technique to solve this. http://ideone.com/jUDihh