CodeMosa

Master LeetCode Patterns

5 Problems

Two Pointers — Advanced

Harder two-pointer problems: water trapping, k-sum variants, and linked-list tricks.

Back to Collections

Relevant Patterns

#
Study these pattern guides before tackling the problems. Understanding the core concepts will help you solve them more efficiently.

Practice Problems

#
Show 2 hints
  • If mismatch at l,r try skipping either side once and check palindrome.
  • Helper isPalindrome(l+1,r) || isPalindrome(l,r-1).
Medium#18
Show 2 hints
  • Sort; fix two indices and two-pointer the remainder.
  • Skip duplicates at every level to avoid repeats.
Show 2 hints
  • Advance fast pointer n steps; then move both until fast hits null.
  • Use a dummy head to simplify edge cases (remove first node).
Show 2 hints
  • Sort; fix i and two-pointer j/k to track closest sum.
  • Update best difference when |sum-target| improves.
Show 2 hints
  • Two pointers with leftMax/rightMax; add water at the lower side.
  • Move the pointer at the lower height inward each step.

Track Your Progress

Mark problems as complete as you solve them. Come back anytime to continue where you left off.