Interview Questions

224. find out how many unique paths to the top right hand corner cell

Microsoft Interview Questions and Answers


(Continued from previous question...)

224. find out how many unique paths to the top right hand corner cell

Question:
1) m * n matrix
2) start from lower left hand cell
3) you can move either up or right
4) find out how many unique paths to the top right hand corner cell.

[][][][][e]
[][][][][]
[s][][][][]

where s= start; e=end;


maybe an answer:


<pre lang="c" line="1" title="CodeMonkey88343" class="run-this">#include<stdio.h>

int main()
{
int len = 3, paths=0;

paths = noOfPaths(len-1,0,0,len-1);
printf("No. of paths = %d", paths);
}


int noOfPaths(int startx, int starty, int endx, int endy)
{
if(startx < endx || starty > endy)
return 0;
if(startx == endx && starty == endy)
return 1;

return (noOfPaths(startx-1, starty, endx, endy) + noOfPaths(startx, starty+1, endx, endy)); }</pre><pre title="CodeMonkey88343" input="yes"> </pre>

(Continued on next question...)

Other Interview Questions