Microsoft Interview Question
Software Engineer in TestsWe can implement this recursively by adding node by node of two link list.
Where:
result=(node1+node2+earlier carry)%10
if((node1+node2)>10) then carry a 1 to the next addition.
Add the tails of the two nodes with passing along with carry.
Expample : List1 : 4->5->6 and List 2 : 4->5->2
Then result = 8->0->9
if by add you mean concatenate them, there are at least 4 separate cases you should test:
- 2 non-empty lists
- 1 non-empty list, 1 empty list, in both possible ordering
- 2 empty lists
depending on what your specifications are, you may also want to test things like whether or not the program deals with circularly linked lists, etc. but of course, ask your interviewer what your arguments will be
I believe by add means add two number represents using link list , if that the case reverse both the link list than start add node by node value from start node and insert in new link list after the addition reverse the resultant link list..
what do you mean by "add two lists"?
- S October 24, 2010