Hi guys,
I am trying to figure out what is the main difference between the Sliding Window and Two-pointer technique.
Seem these topics are being asked in the interview very frequently so understanding them clearly is required.
Could anyone explain the difference and share some coding problems describe the difference?
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.
Any additional comment, advise ?
Super useful links related to those topics:
https://leetcode.com/discuss/general-discussion/657507/Sliding-Window-for-Beginners-Problems-or-Template-or-Sample-Solutions
https://leetcode.com/tag/sliding-window/
https://leetcode.com/articles/two-pointer-technique/
https://leetcode.com/tag/two-pointers/
Thank very much.