Given a Singly Linked List. The task is to check if the absolute difference between the consecutive nodes in the linked list is 1 or not.
Input : List = 2->3->4->5->4->3->2->1->NULL
Output : YES
Explanation : The difference between adjacent nodes in the list is 1. Hence the given list is a Jumper Sequence.
Input : List = 2->3->4->5->3->4->NULL
Output : NO
- Take a temporary pointer to traverse the list.
- Initialize a flag variable to true which indicates that the absolute difference of consecutive nodes is 1.
- Start traversing the list.
- Check if the absolute difference of consecutive nodes is 1 or not.
- If Yes then continue traversal otherwise update flag variable to zero and stop traversing any further.
Below is the implementation of the above approach:
- Maximum sum of K consecutive nodes in the given Linked List
- Absolute Difference of all pairwise consecutive elements in an array
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Sort linked list which is already sorted on absolute values
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Difference between Singly linked list and Doubly linked list
- Delete N nodes after M nodes of a linked list
- Linked List Sum of Nodes Between 0s
- Sum of the alternate nodes of linked list
- Find the sum of last n nodes of the given Linked List
- Sum of all odd frequency nodes of the Linked List
- Linked List Product of Nodes Between 0s
- Sum and Product of all the nodes which are less than K in the linked list
- Find sum of even and odd nodes in a linked list
- Sum of all distinct nodes in a 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 firstname.lastname@example.org. 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.