🚀 Day 21 of my DSA Journey (LeetCode + Java) Today’s practice focused on Array Manipulation + Counting Frequency problems. All three questions looked simple at first, but each required a deeper thought process to get the most optimized solution. ✅ Problems Solved Today LC 66 – Plus One LC 88 – Merge Sorted Array LC 1189 – Maximum Number of Balloons 🧠 My Experience Solving These: 🔸 66. Plus One This problem was trickier than I expected. Initially, I solved it in a non-optimized way. Then I realized the key insight: Traverse from the end If digit < 9, just increment and return If digit is 9 → make it 0 and continue If all digits are 9 → create new array with leading 1 Once I understood this, I solved it in one single loop—clean and efficient. 🔸 88. Merge Sorted Array My first approach used two loops and sorting, but it was: Extra time Not optimal Then I optimized it by using three pointers: i at the end of arr1 j at the end of arr2 k at the final position Compare & place larger element → move pointers. Finally append remaining elements from arr2. This method was fully optimized (O(n)) without any extra space. 🔸 1189. Maximum Number of Balloons This one was fun! I used a HashMap to count frequency of characters. The tricky part was: How to divide counts correctly for repeated characters like 'l' and 'o' After several dry runs, the logic became clear: Count freq of each char in text Count required freq for word “balloon” Divide actual/required → minimum of all divisions = answer A clean and optimal solution. 📌 Key Takeaway Today Even simple array problems can become tricky if we miss the pattern. Today I reinforced: ✔ Think from the end for digit problems ✔ Use three pointers for merging arrays ✔ Frequency-based problems → always check min(actual/required) ✔ Dry run is your best friend Step-by-step progress every day is building my confidence and logical thinking. 💪 On to Day 22! 🚀 #DSA #LeetCode #Java #Arrays #HashMap #ProblemSolving #CodingJourney #Consistency #LearningDaily
LeetCode Practice Day 21: Arrays & HashMap Solutions
More Relevant Posts
-
🚀 Day 25 of my DSA Journey (LeetCode + Java) Today’s practice focused on frequency-based problems, using HashMaps, Priority Queues, and simple array traversal. Each question had a different flavor but all were fun to solve! ✅ Problems Solved Today: LC 347 – Top K Frequent Elements LC 451 – Sort Characters by Frequency LC 414 – Third Maximum Number 🧠 My Experience Solving These: 🔸 347. Top K Frequent Elements A classic frequency + heap problem. First, I created a HashMap to count occurrences Then pushed elements into a max-heap/min-heap based on frequency Extracted the top k frequent elements This problem is a great example of how HashMap + PriorityQueue together give an optimal O(n log k) solution. 🔸 451. Sort Characters by Frequency This was a fun problem because it combines strings with frequency sorting. My steps: Count frequency using HashMap Use a max-heap to sort characters by highest frequency Build the final string by repeating each character its number of times Very satisfying to see the string rearranged cleanly based on frequencies. 🔸 414. Third Maximum Number This one was the simplest among the three. I used a single pass approach: Track the largest, second largest, and third largest values Update them as we scan through the array Return the third max or highest max if not enough distinct numbers exist No sorting needed — an O(n) solution with clean logic. 📌 Key Takeaway Today: Frequency-based problems are powerful and appear everywhere. ✔ HashMap is the backbone ✔ PriorityQueue/Heap helps extract top elements ✔ Many problems reduce to counting + ordering ✔ Always aim for O(n log k) or O(n) instead of sorting everything Feeling more confident every day! On to Day 26! 🚀 #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #CodingJourney #Consistency #LearningDaily
To view or add a comment, sign in
-
Day25 - LeetCode Journey Solved LeetCode 344: Reverse String in Java ✅ This was a simple problem on the surface, but it perfectly highlights how powerful clean logic can be. The goal was to reverse a string in-place using O(1) extra space, which means no extra arrays and no shortcuts. Just pure two-pointer logic. Using the left and right pointers and swapping characters step by step felt very satisfying. It’s one of those patterns that looks small but appears everywhere in interviews and real-world problems. Mastering this makes many string and array problems much easier later on. What I liked about this problem is how it teaches efficiency. Instead of creating new memory, we directly modify the existing array. That mindset of optimizing space is extremely important in DSA. Key takeaways: • Strong practice of the two-pointer technique • In-place operations with constant extra space • Clean and readable swapping logic • Reinforced fundamentals of string manipulation ✅ Accepted successfully ✅ 0 ms runtime with optimal performance Sometimes the simplest problems build the strongest foundations. Consistency with basics is what makes complex problems feel easier later 💪 #LeetCode #DSA #Java #Strings #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #TwoPointers #Consistency #DailyPractice
To view or add a comment, sign in
-
-
🚀 Day 28 of my DSA Journey (LeetCode + Java) Today’s focus was completely on Sliding Window + Hashing patterns. All three problems looked different, but the core logic was about maintaining a valid window and updating the answer efficiently. ✅ Problems Solved Today: LC 3 – Longest Substring Without Repeating Characters LC 424 – Longest Repeating Character Replacement LC 1004 – Max Consecutive Ones III 🧠 My Experience Solving These: 🔸 3. Longest Substring Without Repeating Characters This is a classic sliding window + HashMap problem. Used a HashMap to store last index of characters If a character repeats, moved left pointer smartly Calculated window length using right - left + 1 Very clean logic once the window movement is clear. 🔸 424. Longest Repeating Character Replacement This one was tricky but powerful. Maintained frequency array for characters Tracked the most frequent character (maxCount) If window size – maxCount > k → shrink window Understanding why maxCount doesn’t decrease was the key insight. 🔸 1004. Max Consecutive Ones III Sliding window on array with condition. Count number of zeros in the window If zeros > k → move left pointer Always track maximum window length Simple idea, very effective solution. 📌 Key Takeaway Today: Sliding Window problems are all about maintaining a valid window. ✔ Decide what makes window invalid ✔ Expand using right pointer ✔ Shrink using left pointer ✔ Update answer at every step ✔ Avoid nested loops → O(n) always wins The more I practice, the faster I recognize patterns. 💪 Consistency + daily effort = confidence. On to Day 29 🚀 #DSA #LeetCode #Java #SlidingWindow #HashMap #ProblemSolving #CodingJourney #Consistency #LearningDaily
To view or add a comment, sign in
-
📅 Day 6 out of 100 — Solving LeetCode Problems Daily, Kickstarting My Java + DSA Journey 🚀 📘 Course: Data Structures & Algorithms – Self-Paced 📈 One Problem a Day: Consistency Compounding. Leetcode Problem 69. Sqrt(x) Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. Example 1: Input: x = 4 Output: 2 Explanation: The square root of 4 is 2, so we return 2. Example 2: Input: x = 8 Output: 2 Explanation: The square root of 8 is 2.82842..., and since we round it down to the nearest integer, 2 is returned. Constraints: 0 <= x <= 231 - 1 #leetcode #DSA #java #problemsolve
To view or add a comment, sign in
-
-
Day26 - LeetCode Journey Solved LeetCode 345: Reverse Vowels of a String in Java ✅ This problem was a fun twist on the classic string reversal pattern. Instead of reversing the whole string, the focus was only on vowels, which makes you think a little more carefully about pointer movement and conditions. Using the two-pointer approach here felt really clean. One pointer moves from the start, the other from the end, and both skip non-vowel characters until a valid swap is possible. Simple logic, but very effective. It’s a great example of how a small condition change can turn an easy problem into a nice logical exercise. What I enjoyed most was how this problem strengthens selective traversal. You’re not touching every character blindly, you’re filtering and acting only when needed. That mindset is very useful in optimizing solutions. Key takeaways: • Strong practice of the two-pointer technique • Efficient handling of character filtering • Clean in-place swapping logic • Better understanding of conditional traversal ✅ Solution accepted successfully ✅ Solid performance with clean and readable code Problems like this make string manipulation feel more intuitive and structured. One more step forward in sharpening fundamentals 💪 #LeetCode #DSA #Java #Strings #TwoPointers #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #Consistency #DailyPractice
To view or add a comment, sign in
-
-
Day22 - LeetCode Journey Solved LeetCode 242: Valid Anagram in Java ✅ This problem was a nice reminder of how simple ideas can lead to clean and effective solutions. Checking whether two strings are anagrams really comes down to understanding character frequency and order. By sorting both strings and comparing them character by character, the logic becomes very straightforward and easy to follow. What I liked about this problem is how it strengthens fundamentals of string handling and arrays. It also shows how preprocessing data can simplify the main comparison logic. Small steps like converting strings to character arrays and sorting them make the solution both readable and reliable. Key takeaways: • Better understanding of string to array conversion • Using sorting as a tool to simplify comparisons • Writing clean and minimal logic • Strengthening basics of string manipulation ✅ All test cases passed successfully ✅ Logic kept simple and efficient ✅ Another step forward in building strong DSA foundations Consistency with such problems really builds confidence over time 💪 #LeetCode #Java #DSA #Strings #ValidAnagram #ProblemSolving #CodingJourney #InterviewPreparation #Algorithms #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
Finished working through Arrays & ArrayLists today. This module felt like the point where coding stopped being about Java syntax and started being about how to think. What arrays actually taught me: - indices matter more than the values themselves - in-place operations need careful planning - small boundary mistakes break logic completely - many problems are solved by reusing a few core patterns - breaking a problem into steps makes it manageable - optimization only makes sense after correctness Working with ArrayLists alongside arrays also made the trade-offs clearer — convenience vs control. Problems like rotation, sorting with pointers, and finding missing elements forced me to slow down and reason instead of guessing. This module made me more comfortable with problem-solving and showed me where I still need practice. Moving forward with a better foundation. #Java #DSA #Arrays #LearningInPublic #ProblemSolving #CodingJourney #JavaDeveloper
To view or add a comment, sign in
-
Day 10/25 – LeetCode Challenge 🚀 🔸Problem: Add Strings 🔸Difficulty: Easy 🔸Topic: String, Math 🔸Language: Java Approach 🛠️: ▫️Converted both numeric strings into BigInteger objects. ▫️Used built-in addition to compute the sum safely for large values. ▫️Converted the resulting BigInteger back into a string. ▫️This avoids manual digit-by-digit addition logic. ▫️Efficient for handling very large numbers represented as strings. Key Learnings📚: 🔹Handling large numbers beyond primitive data type limits 🔹Working with string-based numeric inputs 🔹Using Java libraries for precise arithmetic 🔹Understanding constraints vs practical solutions
To view or add a comment, sign in
-
-
LeetCode Daily — Problem #3794: Reverse String Prefix Today’s challenge was a fun string manipulation task: Problem: Given a string s and an integer k, reverse the first k characters and return the resulting string. Example: Input: s = "abcd", k = 2 Output: "bacd" Approach: I converted the string to a character array, reversed the first k characters using a loop, and then appended the rest. Here's the Java solution:✅ Result: Accepted with 0 ms runtime! Takeaway: This problem reinforced how simple logic and clean iteration can solve string-based challenges efficiently. It’s a great reminder that even “Easy” problems can sharpen your fundamentals. #LeetCode #Java #StringManipulation #CodingChallenge #100DaysOfCode #ProblemSolving #LinkedInLearning
To view or add a comment, sign in
-
-
🚀 Day 22 of my DSA Journey (LeetCode + Java) Today’s practice focused on Strings + HashMap + Character Frequency problems. All three questions required pattern-thinking and careful dry runs to avoid mistakes. ✅ Problems Solved Today: LC 205 – Isomorphic Strings LC 2194 – Cells in a Range on an Excel Sheet LC 383 – Ransom Note 🧠 My Experience Solving These: 🔸 205. Isomorphic Strings This problem looked easy at first, but it got complicated quickly. I first tried using one HashMap, but it failed because: One direction mapping is not enough Characters need to map both ways Then I created two HashMaps: map1 → s → t map2 → t → s With this, all cases passed and the solution became fully optimized. A great learning about bidirectional mapping. 🔸 2194. Cells in a Range on an Excel Sheet Initially, I didn’t understand what the problem was asking. Then I realized: Range is like "K1:L2" Columns vary (letters) Rows vary (numbers) Used a simple nested loop: Outer loop: columns Inner loop: rows Once understood, it became an easy and clean solution. 🔸 383. Ransom Note This problem was tricky because of frequency handling. I used an int[26] array to count characters of the magazine. Count frequency Reduce frequency while checking ransom note If any count < 0 → not possible Dry runs helped me catch mistakes and finalize an O(M + N) optimized solution. 📌 Key Takeaway Today: String problems are all about patterns and frequency logic. ✔ Some problems need two-way mapping ✔ Some require simple range expansion ✔ Many become easy if you use frequency arrays / HashMap ✔ Dry runs remove 90% of mistakes Every day my problem-solving mindset is improving. Consistency is building confidence! 💪 On to Day 23! 🚀 #DSA #LeetCode #Java #HashMap #Strings #CodingJourney #ProblemSolving #Consistency #LearningDaily
To view or add a comment, sign in
Explore related topics
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