What is the approach to solve "nested for" loops?
Ex -
for(i=0;i<10;i++)
for(j=i;j<10;j++)
for(k=j;k<10;k++)
for(l=k;l<10;l++)
for(m=l;m<10;m++)
count++;
gives count = 2002..?? (14C5)
I thought of 10 * (10 + 9) * (10 + 9 + 8) ........ *(10+9+8+7+6) which is giving way wrong. Also, I thought of 15C5. But it is also incorrect.
The answer is coming as..
For first loop, it is 10/1
For second loop, it is 10*11/(2*1)
For third loop, its is 10*11*12 / (3*2*1) and so on..
Kindly correct me and provide me with the correct approach to solve such questions as the interviewers always modify such questions..