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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Merge a linked list into another linked list at alternate positions
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- 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
- Write a function to get the intersection point of two Linked Lists | Set 2
- 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
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.