Palindrome Check Using Recursion and Two Pointers

Day 44 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Check Palindrome Using Recursion We were given a string s. Task was to check whether it is a palindrome. But using recursion. 💻 Approach (Recursion + Two Pointers) 🔹️Take two pointers: start and end. 🔹️Base case:   ▪️If start >= end → return true 🔹️Compare characters at start and end. 🔹️If they are not equal → return false 🔹️If equal → move inward   ▪️start + 1   ▪️end - 1 🔹️Call function again for inner substring Keep checking till center. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) Due to recursion stack. 📚 What I learned today: ▫️Recursion can simulate two-pointer traversal. ▫️Base condition defines when to stop checking. ▫️Breaking problem into smaller substrings simplifies logic. ▫️Recursive calls use stack space internally. Day 44 completed. Combining recursion with pointers 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic

To view or add a comment, sign in

Explore content categories