Given an integer k and a linked list, every node of which consists of a pair of integer variable first and second to hold the data, and a pointer pointing to the next node in the list. The task is to find whether the sum of data variables of any of the nodes is equal to k. If yes then print Yes else print No.
Input: (1, 2) -> (2, 3) -> (3, 4) -> (4, 5) -> NULL, k = 5
For the second node, the sum of data variables is 2 + 3 = 5.
Input: (1, 2) -> (2, 3) -> (3, 4) -> (4, 5) -> NULL, k = 15
Approach: Traverse the whole linked list until the sum of elements of a node is equal to the key value. When sum of element of a node is equal to key value then print Yes. If there is no such node whose sum of element is equal to the key value then print No.
Below is the implementation of the above approach:
- Swap Kth node from beginning with Kth node from end in a Linked List
- Create new linked list from two given linked list with greater element at each node
- Insert a node after the n-th node from the end
- Element in a matrix starting from which anti-clockwise traversal ends at the last element
- Find next right node of a given key
- Remove Nth node from end of the Linked List
- Search a node in Binary Tree
- Squareroot(n)-th node in a Linked List
- Remove first node of the linked list
- Remove every k-th node of the linked list
- Linked List | Set 3 (Deleting a node)
- Linked List | Set 2 (Inserting a node)
- Program for n'th node from the end of a Linked List
- Delete Nth node from the end of the given linked list
- Remove last node of the linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.