Count Special Characters with Bit Manipulation

This title was summarized by AI from the post below.

#DSAChallengeDay53 Today’s challenge was a neat exercise in bit manipulation + set intersection logic 🔠⚡ 📌 Problem Solved Today (LeetCode - 3120): Count the Number of Special Characters I ✅ Logic: The task is to count characters that appear in both lowercase and uppercase in the string. I solved this using bit manipulation for efficient tracking: ✅ Traversed the string and tracked lowercase characters using a bitmask ✅ Tracked uppercase characters using a separate bitmask ✅ Used bitwise AND (lower & upper) to find common characters ✅ Counted set bits using Integer.bitCount() to get the final answer 💡 Learnings: 🔹 Bit manipulation is a powerful way to optimize space and speed for character tracking 🔹 Using bitmasks avoids extra data structures like sets/maps 🔹 The intersection of two bitmasks directly gives the required result 🔹 Efficient solution with O(n) time and O(1) space 🚀 This problem reinforced how low-level techniques like bit operations can simplify seemingly straightforward problems and make solutions more elegant. #DSAChallengeDay53 #100DaysOfDSA #LeetCode #LeetCodeDailyChallenge #BitManipulation #Java #DSA #CodingJourney #KeepCoding #OptimizationTricks #geekstreak2025 #personalguidanceprogram #pgpbyanchal

  • text

To view or add a comment, sign in

Explore content categories