🚀 Day 59 of My Consistency Journey Today, I solved String Compression (LeetCode 443) — and honestly, it taught me a powerful lesson about thinking beyond brute force. 🔍 Key Learning: At first, I was tempted to use a HashMap to count frequencies, but that approach fails because this problem is about consecutive characters, not total frequency. 💡 Core Concept: 👉 Use Two Pointers (i & j) i → reads and counts characters j → writes compressed result 📌 Main Idea: "Group → Count → Write" Example: Input: a a a b c c Output: a3 b c2 ⚡ Important Insight: Handling counts like 12 or 15 means writing digits separately ('1', '2'), not as a single number. 🧠 What I Improved Today: Understanding in-place array modification Mastering two-pointer technique Writing optimized and clean logic Consistency is slowly turning confusion into clarity 💯 #Day59 #100DaysOfCode #Java #DSA #LeetCode #CodingJourney #PlacementPreparation #KeepLearning
Solving String Compression LeetCode 443 with Two Pointers
More Relevant Posts
-
🚀 Day 33 of #128DaysOfCode 🧩 Problem Insight: The goal was to check whether a given string can be formed by repeating one of its substrings multiple times. 💡 Key Learning: Instead of checking all possible substrings (which can be inefficient), I learned an elegant trick: By concatenating the string with itself and removing the first and last characters, we can determine if the original string exists within it. ⚡ This approach helped me: - Improve my understanding of string patterns - Learn a smart optimization technique - Avoid brute-force solutions 🛠️ Concepts Practiced: - String manipulation - Pattern recognition - Optimized problem-solving approach 📈 Every day I’m getting better at identifying patterns and writing cleaner, more efficient code. #Day33 #128DaysOfCode #Java #DSA #CodingJourney #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 72 — LeetCode Practice 🚀 Today’s problem: Sorting the Sentence 💡 What I learned today: • Practiced string manipulation and splitting techniques • Understood how to extract numbers from characters using ASCII logic • Learned to map words to correct positions using indexing • Improved attention to detail while handling edge cases 🧠 Key idea: Each word has a number at the end → use it to place the word in the correct position → then remove the number and rebuild the sentence. ✨ Consistency is slowly turning confusion into clarity. #Day72 #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 LeetCode — Problem 242 | Day 14 💡 Problem: Valid Anagram --- 🧠 Problem: Given two strings s and t, return true if t is an anagram of s, otherwise false. --- 🧠 Approach: - First check length: • If lengths differ → not an anagram - Use a frequency array of size 26 - Traverse both strings: • Increment count for s • Decrement count for t - Finally check: • If all values are 0 → valid anagram --- ⚙️ Core Logic: - freq[s.charAt(i) - 'a']++ - freq[t.charAt(i) - 'a']-- 👉 If all counts become zero → both strings have same characters --- ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) (fixed size array) --- ⚠️ Edge Cases: - Different lengths → false - Same characters, different order → true - Completely different strings → false --- 🔍 Insight: Instead of sorting, count character frequency --- 🔑 Key Learning: - Frequency counting is faster than sorting - Fixed-size array gives O(1) space - Simple and optimal approach for character problems --- "Compare frequency of characters using a fixed array instead of sorting." --- #LeetCode #DSA #Java #Strings #CodingJourney
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 33 Today’s focus: Binary Search for next greater element. Problem solved: • Find Smallest Letter Greater Than Target (LeetCode 744) Concepts used: • Binary Search • Upper bound concept • Circular handling Key takeaway: The goal is to find the smallest character strictly greater than a given target in a sorted array. This is a classic upper bound problem: We use binary search to find the first element greater than the target. During search: • If letters[mid] > target, store it as a possible answer and move left • Else move right An important edge case: If no character is greater than the target, we return the first element (circular behavior). Continuing to strengthen binary search patterns and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 65/100 Today’s problem was about cyclic string transformation (index shifting). 🔹 Problem: Encrypt a string by replacing each character with the k-th character ahead in a circular manner. 🔹 Key Learning: - Understood how to use modulo (%) for cyclic traversal - Learned that shifting indices is often easier than modifying characters - Optimized solution using "(i + k) % n" 🔹 Approach: - Loop through the string - For each index, pick the character at "(i + k) % n" - Build the result string 🔹 Time Complexity: O(n) 💡 Small concept, but powerful pattern for many problems involving circular arrays/strings. Consistency > Motivation 💯 #Day65 #100DaysOfCode #Java #DSA #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
🚀 Day 66 of #LeetCode Challenge ✅ Problem Solved: Divide a String Into Groups of Size K 💡 What I learned today: • Learned how to break a string into fixed-size groups • Understood how to handle incomplete groups using a fill character • Practiced building strings step-by-step using loops • Improved clarity on index handling and conditions 🧠 Approach: • Traverse the string one character at a time • Build a group until it reaches size k • Store the group and reset • If the last group is smaller, fill remaining positions with the given character 📊 Key Takeaway: Handling edge cases (like incomplete groups) is very important in problem solving 🔥 Consistency is the key — improving step by step every day! #Day66 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 48 of My #LeetCode Journey Today’s problem: 2615. Sum of Distances 💡 Key Idea: Instead of calculating distances between equal elements using brute force (O(n²)), I used: HashMap to group indices of same values Prefix Sum to efficiently compute distances This reduced the complexity to O(n) 🔥 🧠 What I Learned: How prefix sums can optimize distance calculations Efficient handling of repeated elements Writing clean and optimized code using Java ⚡ Approach: Store indices of each number Use prefix sums to calculate left & right distances Combine both to get final answer 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Consistency is key. Small progress every day leads to big results 💪 #Day48 #Java #FullStackDeveloper #CodingJourney #100DaysOfCode #DSA #LeetCode
To view or add a comment, sign in
-
Day 32 of #50DaysLeetCode Challenge 💻🔥 Today I solved the “Rotate Image” problem using Java. 🔹 Problem: Given an n × n matrix, rotate the image 90° clockwise in-place (no extra matrix allowed). 🔹 Where people mess up: Trying to simulate rotation directly with extra space. That defeats the whole point of the problem. 🔹 Optimal Approach: 1. Transpose the matrix (swap rows & columns) 2. Reverse each row That’s it. Two clean steps. No overthinking. 🔹 Key Insight: Rotation isn’t magic — it’s just a combination of simple transformations. 🔹 Time Complexity: O(n²) 🔹 Space Complexity: O(1) 📌 What I learned: Most matrix problems look complicated until you break them into small predictable operations. If your approach feels messy, you’re probably doing it wrong. Simple > Clever. #Day32#LeetCode #Java #Matrix #DSA #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
Day 92 of #100DaysOfLeetCode 💻✅ Solved #739. Daily Temperatures problem in Java. Approach: • Used Monotonic Stack to track indices • Compared current temperature with stack top • Updated result when a warmer day was found • Stored indices for future comparisons Performance: ✓ Runtime: 60 ms (Beats 79.01% submissions) 🚀 ✓ Memory: 107.89 MB (Beats 17.53% submissions) Key Learning: ✓ Learned Monotonic Stack technique ✓ Improved handling of next greater element problems ✓ Strengthened stack-based problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #Stack #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
“What I learned after solving 300+ LeetCode problems 👇” At the beginning, I made a mistake. I kept solving random problems every day thinking: “More problems = more skill” But I was wrong. I realized that solving problems randomly is mostly a waste of time if you don’t understand the pattern behind them. Everything changed when I started focusing on patterns instead of problems. Here are some important patterns I learned: • Sliding Window • Two Pointers • Prefix Sum • Binary Search • Recursion & Backtracking • Linked List Patterns • Stack & Monotonic Stack • Hashing / Frequency Count Once you understand these patterns: You don’t need to solve 1000 problems. You start recognizing solutions instantly. Now when I see a problem, I don’t panic. I ask: 👉 “Which pattern does this belong to?” That one question changed everything for me. Still learning, but now with direction 🚀 #DSA #LeetCode #Java #BackendDevelopment #CodingJourney
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development