Alternating Characters Challenge Solution in C

🔥 Day 98 of #100DaysOfCode Today’s problem was all about string manipulation and greedy thinking — solving the Alternating Characters challenge. 💡 Problem Summary: Given a string of only A and B, the goal is to make sure no two adjacent characters are the same by deleting the minimum number of characters. 🧠 Approach: Instead of trying all possibilities, I used a simple and efficient strategy: Traverse the string once Compare each character with the previous one If they are the same → increment deletion count ⚡ Key Insight: Every pair of matching adjacent characters contributes exactly 1 deletion. 📊 Complexity: Time: O(n) Space: O(1) 🧪 Example: AAABBB → 4 deletions ABABAB → 0 deletions ✨ What I Learned: Sometimes the simplest greedy approach beats complex logic. Recognizing patterns in strings is a powerful skill in problem-solving! 💻 Language Used: C #Day98 #100DaysOfCode #CodingChallenge #DataStructures #Algorithms #CProgramming #ProblemSolving #DeveloperJourney

To view or add a comment, sign in

Explore content categories