Given a Linked List, we have to delete N numbers of nodes after the M numbers of nodes.
Example:
Input: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 → 10
N=2, M=3
Output: 1 → 2 → 3 → 6 → 7 → 8
Input: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 → 10 → 11
N=3, M=3
Output: 1 → 2 → 3 → 7 → 8 → 9
Algorithm:
To solve that problem we simply use the Brute-Force method. We traverse the linked list from the head node and delete N nodes after traversing M nodes. If there are less than N nodes to delete then we simply delete that nodes and stop traversing.
C++ implementation:
Output