Is two pointer problem same as sliding window

Viewed 6698

I was wondering about the significant difference between 'sliding window' and 'two pointer' problem.

It is giving me a hard time to differentiate between the two.

1 Answers

Sliding window algorithms can be implemented with a single pointer and a variable for window size. Typically we use all of the elements within the window for the problem (for eg - sum of all elements in the window).

Two pointer technique is quite similar but we usually compare the value at the two pointers instead of all the elements between the pointers.

Two pointers can also have variations like fast-slow pointer.

Hope it answers your question.

Related