Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Sorting Searching & DP
Data Structures & Algorithms / Arrays & Strings

Two pointers

Learn Two pointers in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.

12 min read • Beginner
data-structures-algorithms-014.py
python
a=[1,2,4,7,11]
target=9
left,right=0,len(a)-1
while left<right:
    s=a[left]+a[right]
    if s==target: break
    if s<target:left+=1
    else:right-=1
print(a[left],a[right])
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content