Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:22:53+00:00 2026-06-03T09:22:53+00:00

I have a problem asked to me in an interview, this is a similar

  • 0

I have a problem asked to me in an interview, this is a similar problem I found so I thought of asking here. The problem is

There is a robot situated at (1,1) in a N X N grid, the robot can move in any direction left, right ,up and down. Also I have been given an integer k, which denotes the maximum steps in the path. I had to calculate the number of possible ways to move from (1,1) to (N,N) in k or less steps.

I know how to solve simplified version of this problem, the one with moves possible in only right and down direction. That can be solved with Dynamic Programming. I tried applying the same technique here but I don’t think it could be solved using 2-dimensional matrix, I tried a similar approach counting possible number of ways from left or up or right and summing up in down direction, but the problem is I don’t know number of ways from down direction which should also be added. So I go in a loop. I was able to solve this problem using recursion, I could recurse on (N,N,k) call for up, left and k-1, sum them up but I think this is also not correct, and if it could be correct it has exponential complexity. I found problems similar to this so I wanted to know what would be a perfect approach for solving these types of problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:22:55+00:00Added an answer on June 3, 2026 at 9:22 am

    Suppose you have an NxN matrix, where each cell gives you the number of ways to move from (1,1) to (i,j) in exactly k steps (some entries will be zero). You can now create an NxN matrix, where each cell gives you the number of ways to move from (1,1) to (i,j) in exactly k+1 steps – start off with the all-zero matrix, and then add in cell (i,j) of the previous matrix to cells (i+1, j), (i, j+1),… and so on.

    The (N,N) entry in each of the k matrices gives you the number of ways to move from (1,1) to (i,j) in exactly k steps – all you have to do now is add them all together.

    Here is an example for the 2x2 case, where steps outside the 
    matrix are not allowed, and (1,1) is at the top left.
    In 0 steps, you can only get to the (1,1) cell:
    
    1 0
    0 0
    
    There is one path to 1,1. From here you can go down or right,
    so there are two different paths of length 1:
    
    0 1
    1 0
    
    From the top right path you can go left or down, and from the
    bottom left you can go right or up, so both cells have paths
    that can be extended in two ways, and end up in the same two
    cells. We add two copies of the following, one from each non-zero
    cell
    
    1 0
    0 1
    
    
    giving us these totals for paths of length two:
    
    2 0
    0 2
    
    There are two choices from each of the non-empty cells again 
    so we have much the same as before for paths of length three.
    
    0 4
    4 0
    
    Two features of this are easy checks:
    
    1) For each length of path, only two cells are non-zero, 
    corresponding to the length of the path being odd or even.
    
    2) The number of paths at each stage is a power of two, because
    each path corresponds to a choice at each step as to whether to 
    go horizontally or vertically. (This only holds for this simple 
    2x2 case).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem similar to this question which was previously asked but my
O.K. Maybe I have asked something similar to this, but this is another problem
I have asked this question before and the problem was half solved in the
I've been into this problem for a while already, and have asked some questions
I don't know if some one asked this but I have a problem that
I was asked this problem in a interview: Best Time to Buy and Sell
I know similar questions have been asked many times befor, but I think this
I was asked this question in an interview today. I have tried a solution
I can't figure this interview question. You have an array of integers. You need
This is an interview problem I was asked, and I am still trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.