They've mentioned that they're large lists. What if it is a 15 digit number? Its not efficient then.
On Wed, Aug 25, 2010 at 8:29 PM, Sathaiah Dontula <[email protected]>wrote: > @Raj, > > How about doing like below ? > > Convert A to base 10 number, numA > Convert B to base 10 number, numB, > Then take the difference numC = abs(numA - numB), > Then convert numC to linked list with the digits > > any comments ?, overflow condition is the problem here. > > Thanks & regards, > Sathaiah Dontula > > On Wed, Aug 25, 2010 at 3:24 PM, Raj N <[email protected]> wrote: > >> Input : Two large singly linked lists representing numbers with most >> significant digit as head and least significant as last node. >> Output: Difference between the numbers as a third linked list with >> Most significant digit as the head. >> Eg: >> --- >> Input: >> A = 5->4->2->0->0->9->0->0 >> B = 1->9->9 >> Output: >> C = 5->4->2->0->0->7->0->1 >> Required complexity : >> O(n) >> Constraint: >> Reversing linked list is NOT allowed >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<algogeeks%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
