There is an infinite line. You are standing at a particular point you can either move 1 step forward or 1 step backward. You have to search for an object in that infinite line. Your object can be in any direction. Give an optimal solution
Go 1 step forward, 2 step back ward Go 2 step forward, 4 step back ward and so on
Lets say the required object is at point n.
Total number of steps:
3 + 6 + 9 + .... n = 3(1 + 2 + 3 ... n) = O(n^2)
Is there a way to improve the efficiency?