The two-pointer technique can be used to solve many a interviewing problems and I decided to write a poem to show some of the ways it can do that.
“Infront of you is bkk, ready to present to you a poem entitled “An Ode to the Two Pointer Technique”. Sit back, relax and enjoy”
When asked to check if the string is a palindrome,
Turn to a trusted friend,
1 pointer at the start and one at the end,
Move both towards the middle checking each letter,
Comparing only alpha-numeric characters is better,
If the letters at each position match,
Then the string is a catch.
When asked to find the middle of linked list,
Place a tortoise and a hare at the start,
The first goes slow, the latter goes fast,
The tortoise jumps 1 step, the hare jumps 2,
When the bunny reaches the end, the tortoise will have a clue,
About where the center lies,
The two pointer never lies
PREVIOUSReason v. Feelings (2020)