Trilogy Interview Question
Software Engineer / DevelopersLet we have two numbers num1 & num2....
num1 is size of m bytes..
num2 is size of n bytes...
dividelist (list *numx, sizeint x, list *numy, sizeint y)
{
list *tempremainder, *tempquotient;
tempquotient = divnum(numx, x-y+1, numy[0]+1 );
limit = divnum(numx, x-y+1 ,numy[0]);
tempquotient = tempquotient+1;
mul1 = multiply (numy, tempquotient));
mul2 = multiply (numy, tempquotient1));
while(tempquotient1 <= limit)
{
if(mul2>numx)
break;
tempquotient =tempquotient1;
tempquotient1++;
mul1 = mul2;
mul2 = multiply (numy, tempquotient1));
}
remainder = subtract(numx , multiply (numy,tempquotient));
quotient = tempquotient;
}
Here ,.. multiply , subtract & increment , can be done simply.. as everybody know.. for two numbers contained in linked lists.. However the complexity would be large enough...
Main Concept : is to divide the first .. m-n+1 segments of first number.. by the first single segment of second number...
so the quotient would be.. between the numbers from ( m-n+1 segments , divided by single first segment of numy) and (m-n+1 segments of numx , divided by single first segement of numy with increment 1)...
My Query is: How this "m-n+1" terms are decided(What is the logic behind choosing this figure) I worket out on this problem....but not able to understand the first "m-n+1" bytes selection logic. Please, give ur suggestion, u can also suggest ur own method as well.
use linked list
- Anonymous September 08, 2011