In this method, we’ll have two pointers p and q. p will initially point to the head of the list and q to the last node of the list. Next, we’ll check the data elements at each of these nodes that are being pointed to by p and q and see if they are equal to each other. If they are, we’ll progress p by one, and we’ll move q by one in reverse until we get to a point where p and q either meet or essentially can’t move any further without crossing.
Implementation
Let’s jump to the coding part now.