LeetCode POTD | Day 58 3120. Count the Number of Special Characters I Today’s problem was based on character tracking and set operations. We had to count how many characters appeared in both lowercase and uppercase forms inside the string. My approach: • Used a HashSet<Character> to keep track of visited characters • Traversed the string character by character • Checked whether the opposite case version of the current character already existed in the set • If both lowercase and uppercase versions were present, increased the count • Added every processed character into the set for future checks The ASCII-based case conversion made the implementation shorter and efficient without needing extra helper functions. What I learned today: • Sets are extremely useful for fast character lookup • ASCII operations can simplify character conversion logic • Small string problems still require careful condition handling • Keeping the solution simple often leads to cleaner code • Character manipulation problems become easier with pattern observation #LeetCode #DSA #Strings #HashSet #Java #ProblemSolving #CodingJourney #Algorithms #LeetCodeDailyChallenge
Counting Special Characters in LeetCode Challenge
More Relevant Posts
-
Code Notes #09 LeetCode 3120- Count the Number of Special Characters I The problem requires identifying letters that appear in both lowercase and uppercase within a given string and returning their count. Approach: - Stored all characters in a HashSet for O(1) lookups. - Iterated through the 26 letters of the alphabet, checking whether both the lowercase and uppercase variants existed in the set. - Leveraged ASCII arithmetic (c - 32) to derive the uppercase counterpart without any built-in conversion methods. Time Complexity: O(n) for building the set, O(1) for the fixed 26-letter check. #LeetCode #DataStructures #Algorithms #Java #CodingInterview #ProblemSolving #CompetitiveProgramming #SoftwareEngineering
To view or add a comment, sign in
-
-
Just wrapped up solving LeetCode 1861: Rotating the Box using an optimized two-pointer + matrix rotation approach in Java. �� Problem Highlights Rotate the box 90° clockwise Simulate gravity on stones (#) Obstacles (*) remain fixed Goal: achieve optimal traversal without unnecessary simulations Key Insight Instead of: Rotating the matrix Then applying gravity separately I merged both operations into a single traversal. Using: Right-to-left scanning An empty pointer Direct placement into rotated coordinates Result: ✅ O(m × n) Time Complexity ✅ Clean implementation ✅ 99.52% runtime performance on LeetCode ⚡ This problem is a great example of how recognizing coordinate transformations can eliminate redundant work entirely. Tiny optimization. Massive efficiency gain. That’s the kind of engineering dopamine we chase. 😄 #LeetCode #DSA #Java #Algorithms #CodingInterview #SoftwareEngineering #ProblemSolving #Tech #Programmer #DataStructures #100DaysOfCode
To view or add a comment, sign in
-
-
Today’s LeetCode Daily Problem 💻 LeetCode 3121. Count the Number of Special Characters II => Problem Task: Count Special Characters. For a character to be special, two conditions must be satisfied: • It must appear in both lowercase and uppercase. • All lowercase occurrences must come before the first uppercase occurrence. => Constraints: 1 <= word.length <= 2 * 10^5 Checking all lowercase-uppercase pairs manually would lead to an O(n^2) approach: (2 * 10^5)^2 > 10^8, which is far beyond acceptable limits. => Core Intuition: Instead of checking every pair manually, we only need: • the last occurrence of each lowercase character • the first occurrence of each uppercase character If last lowercase index < first uppercase index, then every lowercase occurrence naturally appears before every uppercase occurrence, making that character special. => One small optimization I used: Instead of initializing arrays with -1, I kept the default 0 initialization and stored indices as i+1. This avoids extra initialization work while also helping differentiate between: • 0 -> character not present • >0 -> valid stored index => Complexity • Time Complexity: O(N) • Space Complexity: O(1) => My Step-by-Step Detailed Solution with Dry Run: https://lnkd.in/eFX7iu6e Feel free to share your approach in the comments. #leetcode #leetcodedailycodingchallenge #java #dsa #programming #coding #softwareengineering #competitiveprogramming #algorithms #computerscience
To view or add a comment, sign in
-
-
Day18: 100 days of leetcode Using bit manipulation with two variables (ones and twos) to simulate a modulo-3 counter for each bit position. This cleverly tracks how many times each bit has appeared without using extra space. This is one of those problems that really tests your understanding of bit-level operations. Feels great when the solution clicks! 💡 #LeetCode #Coding #BitManipulation #DataStructures #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day-7/50 LeetCode challenge. 🚀Today’s challenge: Max Points on a Line. This one was a great exercise in precision! The goal is to find the maximum number of points that lie on the same straight line given an array of coordinates. 📌Key Takeaways: The Slope Formula: Used a custom gcd (Greatest Common Divisor) function to represent slopes as irreducible fractions. This avoids floating-point precision issues that can break the logic. Hash Maps for Tracking: Leveraged a Map to track how many points share the same slope relative to an "anchor" point. Edge Cases: Accounted for overlapping points and vertical lines. #50DaysOfCode #LeetCode #Java #DSA #ProblemSolving #Mathematics #SoftwareEngineering #Consistency #PaavaiEngineeringCollege #TechJourney
To view or add a comment, sign in
-
-
Recently, I solved an intriguing LeetCode Hard problem — “Subarrays with K Different Integers” (Leetcode #992). This challenge provided a valuable exercise in deepening my understanding of the Sliding Window pattern, particularly how frequency mapping and window shrinking work together efficiently. One of the most interesting aspects was applying the concept: Count of subarrays with exactly K distinct elements = (at most K) − (at most K − 1). Engaging with problems like this enhances problem-solving approaches and pattern recognition, which are crucial for coding interviews and backend engineering. #LeetCode #Java #ProblemSolving #SlidingWindow
To view or add a comment, sign in
-
🚀 Day 85 of consistency — and a major milestone unlocked: 120 LeetCode problems solved this year! 🔥 Today, I focused on Longest Palindromic Substring (LeetCode 5) using the Expand Around Center approach in Java. Instead of brute-forcing every substring with (O(n^3)) complexity, the key insight was recognizing a palindrome’s symmetry. 💡 Core Idea Every palindrome expands from a center: • Odd length → center is a character (aba) • Even length → center is between characters (abba) By expanding outward while characters match, I reduced the solution to: ✅ Time Complexity: (O(n^2)) ✅ Space Complexity: (O(1)) 📊 Today's Stats • Runtime: 18ms • Memory: 43.42 MB • Current Streak: 85 Days 🔥 • Total Solved: 120 Problems This problem reinforced an important lesson: Strong problem-solving comes from identifying patterns, not memorizing solutions. Next goal: keep sharpening pattern recognition for interviews and scalable thinking. What’s your favorite string algorithm or interview pattern to solve? 👇 #DSA #Java #LeetCode #SoftwareEngineering #CodingInterview #Algorithms #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 22/150 of #150DaysOfCode 🚀 Today’s LeetCode challenge: 👉 “Count the Number of Special Characters” 📌 Problem Overview: A letter is considered special if it appears in both lowercase and uppercase forms within the same string. 💡 Strategy Used: ✅ Utilized HashSet for fast and efficient lookups ✅ Stored lowercase and uppercase characters separately ✅ Compared both sets to count special characters 🧠 Concepts Strengthened: HashSet implementation in Java Character handling using Character class Writing optimized and clean code ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 📈 Day by day, the goal is not just solving problems — it’s becoming better at thinking, optimizing, and growing as a developer 💯🔥 #150DaysOfCode #Day22 #LeetCode #Java #DSA #CodingJourney #Programming #Developer #ProblemSolving #CodeEveryday
To view or add a comment, sign in
-
-
🚀 Day 605 of #750DaysOfCode🚀 Solved LeetCode 3121: Count the Number of Special Characters II 💡 Today’s problem was an interesting extension of the previous special characters problem with an additional ordering condition. 🔹 Key Insight: A character is special only if: it appears in both lowercase and uppercase ALL lowercase occurrences come before the FIRST uppercase occurrence To solve this efficiently, I tracked: last occurrence of lowercase letters first occurrence of uppercase letters Then checked whether: lastLower[i] < firstUpper[i] 📌 Concepts Practiced: Strings Arrays Character Indexing First & Last Occurrence Tracking Traversal ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Medium problems often test how well we observe conditions and optimize tracking efficiently. 💪🔥 #Java #LeetCode #DSA #Programming #Algorithms #SoftwareEngineering #CodingJourney #Developer #Strings #ProblemSolving
To view or add a comment, sign in
-
-
98/100 Completed ✅ 🚀 Solved LeetCode: Minimum Number of Arrows to Burst Balloons (Java) ⚡ Implemented a greedy approach by sorting intervals based on end points and efficiently determining the minimum arrows needed to burst all balloons with optimal overlap handling. 🧠 Key Learnings: • Greedy strategy for interval-based problems • Sorting by end coordinates to minimize arrow usage • Identifying overlapping intervals to reuse a single arrow • Efficient one-pass traversal after sorting 💡 This problem is a classic interval merging variation — instead of merging, we minimize resources (arrows) by choosing optimal end points. Time Complexity: O(n log n) Space Complexity: O(1) Profile : https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #greedy #coding #problemSolving #100DaysOfCode
To view or add a comment, sign in
-
Observe the pattern my frd 😁