Exercise: Sum Two Linked Lists

Sumit Rawal answered on May 18, 2023 Popularity 3/10 Helpfulness 1/10

Contents


More Related Answers

  • Check if two linked lists merge. If so, where?
  • sum nodes in linkedlist
  • sum of nodes in linked list javascript
  • Write an algorithm to create a doubly-linked list and addition of elements to it.
  • Write a java program to merge three singly linked list elements
  • Add two numbers as a linked list
  • merge two sorted linked list
  • Linked Lists - Sorted Merge
  • sum two linked lists if numbers are reversed in linked list
  • merge point of two linked list
  • add two numbers represented by linked lists in rails
  • add two numbers represented by linked lists in rails
  • Solution Review: Sum of Lists
  • how to search through a list for two numbers that sum to make an external input in python
  • Develop a C function to marge two singly linked list in to one linked list.
  • merge sort and linked list
  • add two numbers linked list
  • merge two linked list

  • Exercise: Sum Two Linked Lists

    0

    Problem

    In this exercise, you are required to sum two linked lists and return the sum embedded in another linked list.

    The first number that we append to the linked list represents the unit place and will be the least significant digit of a number. The next numbers appended to the linked list will subsequently represent the tenth, hundredth, thousandth, and so on places.

    For example,

    llist1 = LinkedList()

    llist1.append(5)

    llist1.append(6)

    llist1.append(3)

    in the code above, llist1 represents the number 365.

    Note that you will not be tested on numbers whose sum requires an additional digit.

    Below is an illustration to make the task clearer to you:

    Singly Linked List: Sum Two Lists

    1 of 3

    As you can see from the illustration above, we have two linked lists from which we calculate the sum, and the third linked list represents that sum.

    Coding Time!

    In the code below, the sum_two_lists is a class method of the LinkedList class. You cannot see the rest of the code as it is hidden. As sum_two_lists is a class method, please make sure that you don’t change the indentation of the code provided to you. You are required to write your solution under the method prototype.

    The two linked lists that you have to sum are llist and the linked list on which the method sum_two_lists is called. You will return the third linked list from the method where the data values in that linked list will represent the sum.

    Keep in mind that the linked lists can be of different sizes.

    Good luck! 

    Popularity 3/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Tags: sum whatever
    Link to this answer
    Share Copy Link
    Contributed on May 18 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.