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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum sum of K consecutive nodes in the given Linked List
- Find the string formed by joining k consecutive nodes of linked list
- Delete N nodes after M nodes of a linked list
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Check if a linked list is Circular Linked List
- Difference between Singly linked list and Doubly linked list
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Absolute Difference of all pairwise consecutive elements in an array
- Sort linked list which is already sorted on absolute values
- Absolute distinct count in a Linked List
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Convert singly linked list into circular linked list
- Convert Singly Linked List to XOR Linked List
- Create new linked list from two given linked list with greater element at each node
- Delete alternate nodes of a Linked List
- Reverse alternate K nodes in a Singly Linked List
- Segregate even and odd 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 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.