Given a linked list with distinct elements, the task is to find the bitonic point in the given linked list. If there is no such point then print -1.
Input: 1 -> 2 -> 3 -> 4 -> 3 -> 2 -> 1 -> NULL
1 -> 2 -> 3 -> 4 is strictly increasing.
4 -> 3 -> 2 -> 1 -> NULL is strictly decreasing.
Input: 97 -> 98 -> 99 -> 91 -> NULL
Approach: A Bitonic Point is a point in bitonic sequence before which elements are strictly increasing and after which elements are strictly decreasing. A Bitonic point doesn’t exist if array is only decreasing or only increasing. So, find the first node such that the value of the node next to it is strictly smaller. Start traversing the linked list from that node onwards and if every other node is strictly smaller than its previous node then the found node was out bitonic sequence else the given linked list doesn’t contain a valid bitonic sequence. Note that an empty list or a list with a single node doesn’t represent a valid bitonic sequence.
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.
- Point to next higher value node in a linked list with an arbitrary pointer
- Point arbit pointer to greatest value right side node in a linked list
- Create new linked list from two given linked list with greater element at each node
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular 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
- Check if a linked list is Circular Linked List
- Convert Singly Linked List to XOR Linked List
- Write a function to get the intersection point of two Linked Lists | Set 2
- Write a function to get the intersection point of two Linked Lists
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Find intersection point of two Linked Lists without finding the length
- Construct a Doubly linked linked list from 2D Matrix
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Length of longest palindrome list in a linked list using O(1) extra space
- Rotate the sub-list of a linked list from position M to N to the right by K places
- Linked List Implementation in C#
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.