Two Pointers, Palindromes, and Pair Programming with AI: How I Use LeetCode and ChatGPT to Level Up

image of robot with laptop

“AI isn’t a cheat code. It’s a mirror, a mentor, a sparring partner. But I still have to do the reps.”

LeetCode is more than just a platform to prep for interviews—it’s my personal gym for becoming a better engineer. Every coding challenge is a sparring match. And lately, I’ve been bringing in a tough—but encouraging—partner: AI.

Today’s Challenge: Is It a Palindrome?

The problem seemed simple:

Given a string, determine if it’s a valid palindrome. Ignore case and non-alphanumeric characters.

Sounds easy, right? But this was more than a logic puzzle—it became a masterclass in optimizing space complexity and understanding my weak spots.

Before jumping into code, I grabbed a pen and notebook.

🧠 My Initial Plan:

  • Lowercase the string.
  • Remove all non-alphanumeric characters.
  • Reverse it.
  • Compare with the original.

Here’s my brute-force solution:

✅ It worked.
⛔ But it used O(n) space to create the reversed string.

Enter: My AI Pair Programmer

That’s when ChatGPT nudged me:

“Want to optimize for O(1) space? Try using two pointers.”

I paused. I’d heard of the two-pointer technique, but using it for string validation—especially with regex filtering—was new territory.

So I slowed down, thought through the logic, and wrote pseudocode:

Writing out the steps clarified everything. It forced me to anticipate edge cases and avoid getting lost in loops or syntax midway.

The Final Optimized Solution

With the pseudocode clear, ChatGPT and I sparred a bit more—mostly on regex usage and pointer movement. After a few tweaks, here’s what I landed on:

✅ O(n) time
✅ O(1) space
✅ Confidence boosted

📌 Key Takeaways

  • Sketch First, Code Second: Writing out my plan kept me from prompting blindly or running in circles.
  • Know Where You Struggle: This session revealed my gaps in while loops and regex—now they’re on my radar.
  • ChatGPT as a Mirror: It didn’t give me the answer. It forced me to understand the question more deeply.

🎓 Bonus: The Anki Flashcard

To lock in what I learned, I created an Anki flashcard:

  • Front: The LeetCode prompt.
  • Back: My plain-English explanation, the optimized solution, and its complexity breakdown.

Why? Because learning compounds. And spaced repetition is one of the best investments I can make in my future self.


Final Thoughts: AI Can’t Do the Reps for You

Tools like ChatGPT aren’t shortcuts. They’re clarity amplifiers. They help me surface my assumptions, test my logic, and build real understanding—not just pass a test case.

I still need to sit down, sketch, wrestle with logic, and get it wrong before I get it right. But I don’t have to do it alone.

Whether you’re grinding LeetCode, building side projects, or just learning to think like an engineer, I hope this encourages you to treat AI like what it is: a mentor who never gets tired.

Leave a Reply

Your email address will not be published. Required fields are marked *