Hide Index
- Understanding insertion at beginning
- Insert at beginning
- Understanding insertion at end
- Insert at end
- Understanding insertion after the given node
- Insert after the given node
- Understanding insertion before a given node
- Insert before the given node
- Understanding insertion at a given distance
- Insert at given distance
- Understanding deletion of first node
- Delete first node
- Understanding deletion of last node
- Delete last node
- Understanding deletion by given data
- Delete node with given data
- Delete nodes with given data
- Understanding deletion after a given node
- Delete node after the given node
- Understanding deletion before a given node
- Delete node before the given node
- Understanding deletion of the given node
- Delete the given node
- Understanding deletion at a given distance
- Delete node at given distance
Identifying reversal subproblem
Some problems may consist of smaller subproblems that can be solved using the reversal technique. Solving these subproblems may either partially or fully solve the original problem. These are usually medium or hard problems, as breaking down a problem into subproblems may not be obvious and may require some critical observation. These problems are also implementation-heavy, meaning the solution code is often big and complex, which makes it error-prone.
Asking yourself the following questions will help you determine whether a problem is a reversal subproblem pattern problem or not.
Q1. Can the problem or solution be broken down into smaller subproblems?
Q2. Can any subproblem be solved by reversing a part of the linked list?
Example
Let's consider an example problem and see how to break it down into smaller subproblems that can be solved using the reversal algorithm to understand it better.
Problem statement: Given a doubly linked list, reverse the list in groups of K in-place. If the last group in the list does not have K nodes, don't reverse it.
Liking the course? Check our discounted plans to continue learning.