Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given N*M grid in which one cell contains a ball and all other cells are empty in all other boxes i am provided with one of these 8 directions towards the right position of ball.These are :

1.Exactly Above it
2.Exactly Below it
3.Exactly To the Right
4.Exactly To the Left
5.In the Top Right Region
6.In the Bottom Right Region
7.In the Top Left Region
8.In the Bottom Left Region

How to find the ball in minimum moves.So we need to tell minimum moves required to find the ball.

Note : N and M can go upto 10^19 so we cant make a 2D Grid and then solve.

EXAMPLE : If N=3 and M=3 then here minimum moves is 1

share|cite|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.