Needle In a Haystack problem

http://www.hackerearth.com/problem/algorithm/a-needle-in-the-haystack-1/