Identifying the two pointer pattern


Almost all two-pointer array problems can be formulated as doubly linked list problems and solved similarly using the two-pointer technique. These are generally medium or hard problems, as implementing the two-pointer solution for a doubly linked list is more cumbersome as we must deal with pointers and do null checks. 

If the problem statement or its solution follows the generic template below, it can be solved by using the two-pointer technique.

Template:

Given a doubly linked list, perform some operations on two nodes left and right and where left starts at x and right starts at y such that x < y and with each iteration left and right come closer to each other by some steps.

Liking the course? Check our discounted plans to continue learning.