InterviewSolution
| 1. |
How Do Add Two Numbers Represented Using Linked List In Java? |
|
Answer» You have given two numbers represented by two linked LISTS, write a function that RETURNS the sum of these two lists. The sum list is linked list representation of addition of two input numbers. There are two restrictions to solve this problem i.e. you cannot modify the lists and you are not allowed to use explicit extra space. You can use recursion to solve this problem. Input: First List: 1->2->3 // represents number 123 Second List: 9->9->9 // represents number 999 Output: Resultant list: 1->1->2->2 // represents number 1122 That's all about some of the frequently asked linked list based coding questions from Programming Interviews. As I said, linked list is one of the essential data STRUCTURE and you should have a good command over it, especially if you are PREPARING for Google or Amazon job interview. Once you solve these problems, you can try SOLVING questions given in Algorithm Design Manual by Steven S. Skiena. They are tougher but can really improve your data structure and algorithm skills. You have given two numbers represented by two linked lists, write a function that returns the sum of these two lists. The sum list is linked list representation of addition of two input numbers. There are two restrictions to solve this problem i.e. you cannot modify the lists and you are not allowed to use explicit extra space. You can use recursion to solve this problem. Input: First List: 1->2->3 // represents number 123 Second List: 9->9->9 // represents number 999 Output: Resultant list: 1->1->2->2 // represents number 1122 That's all about some of the frequently asked linked list based coding questions from Programming Interviews. As I said, linked list is one of the essential data structure and you should have a good command over it, especially if you are preparing for Google or Amazon job interview. Once you solve these problems, you can try solving questions given in Algorithm Design Manual by Steven S. Skiena. They are tougher but can really improve your data structure and algorithm skills. |
|