Welcome to the daily solving of our PROBLEM OF THE DAY with Ayush Tripathi We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Linked List but also build up problem-solving skills.
Given a single linked list, calculate the sum of the last n nodes.
Note: It is guaranteed that n <= number of nodes.
Examples:
Input: Linked List: 5->9->6->3->4->10, n = 3
Output: 17
Explanation: The sum of the last three nodes in the linked list is 3 + 4 + 10 = 17.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/find-the-sum-of-last-n-nodes-of-the-linked-list/1