Avrêbarra~
LN2: Two Pointers
- Written on December 8, 2023

Again with the Learning Notes series, where I take the time to document my reviews of LeetCode things. These articles serve as a my record of efforts to enhance my logical abstraction skills and solidify my understanding of important concepts.

Today I’m writing about this Two Pointers concept. This technique involves the use of two pointers to efficiently navigate through data structures, providing an elegant solution to a variety of problems.

Two Pointers Concept

At its core, the Two Pointers approach involves employing two pointers to traverse an array or sequence simultaneously. This technique is particularly powerful when dealing with ordered data. By manipulating the pointers strategically, we can efficiently address various problems.

The mechanics of the Two Pointers approach are straightforward. The two pointers traverse the data in a coordinated manner, converging or diverging based on the problem requirements. This synchronized movement allows us to identify specific patterns or conditions in the data efficiently.

Key Factors Considerations

Several factors influence the implementation of the Two Pointers technique:

Sample Use Cases

The Two Pointers approach finds application in various scenarios, including:

There are also some popular abstractions that looks like a two pointers like sliding windows and slow-fast traversals. Maybe there are others too.

Closing Words

In summary, the Two Pointers approach is another interesting abstractions in problem-solving, particularly in scenarios involving ordered data structures. Hope these insights and techniques become valuable additions to my problem-solving arsenal.

PS: Ah also, in my review, I also got a bit curiosity sparks from sorted arrays.

This data format has some interesting properties, one that rose to me is that this format allows for a implementation where pointers move in opposite directions, and narrows down the search space. Ingenious! Akin to the principles of binary search.

Really interesting this one lad, haha.