🚀 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
Day 22 of DSA Journey: Strings, HashMap, and Frequency Problems
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
-
🚀 Day 29 of my DSA Journey (LeetCode + Java) Today’s focus was on Prefix Sum + Hashing — a powerful combination for solving subarray problems efficiently. Once I understood how prefix sums and hash maps work together, these problems became much clearer and more optimized. ✅ Problems Solved Today: LC 523 – Continuous Subarray Sum LC 325 – Maximum Size Subarray Sum Equals k LC 974 – Subarray Sums Divisible by K 🧠 My Experience Solving These: 🔸 LC 523 – Continuous Subarray Sum This problem was tricky at first. I learned that if two prefix sums have the same remainder when divided by k, the subarray between them is divisible by k. Using a HashMap to store remainder and index helped me solve this in O(n) time. 🔸 LC 325 – Maximum Size Subarray Sum Equals k Here, the goal was to find the longest subarray with sum k. I used prefix sum + HashMap and stored the first occurrence of each sum to maximize subarray length. Simple idea, but very powerful. 🔸 LC 974 – Subarray Sums Divisible by K This problem focused on counting subarrays. Instead of storing indices, I stored frequency of remainders in a HashMap. Each repeated remainder formed valid subarrays divisible by k. 📌 Key Takeaway Today: Prefix Sum + Hashing can solve many subarray problems efficiently. ✔ Convert subarray logic into prefix sums ✔ Use HashMap to track sums or remainders ✔ Handle negative values carefully ✔ One pass → O(n) optimized solutions Every day I’m learning how to recognize patterns faster and write cleaner, optimized code. 💪 On to Day 30 🚀 #DSA #LeetCode #Java #PrefixSum #HashMap #ProblemSolving #CodingJourney #Consistency #LearningDaily
To view or add a comment, sign in
-
Day 11 ( DSA using Java) To strengthen my foundation in Data Structures and Algorithms, I’m committing to solving and sharing LeetCode problem in regular periods of time, along with my thought process and approach. Writing it out helps me learn better and opens the door to meaningful discussion. 🔹 Problem: Q1662 > check if two String Arrays are equivalent 🔹 Core Concept: String , String Functions. solution : public class StringLC { public static boolean arrayStringsAreEqual(String[] word1, String[] word2) { if(String.join("",word1).equals(String.join("",word2))){ return true; } return false; } public static void main(String[] args) { String[] word1 = {"ab","c"}; String[] word2 = {"a","bc"}; System.out.println(arrayStringsAreEqual(word1, word2)); } } I’ve included my solution and time–space complexity analysis. I’d love to hear how others approached this problem—were there alternative or more efficient strategies? Let’s learn, improve, and grow together. #LeetCode #DSA #ProblemSolving #CodingJourney #SoftwareEngineering #LearningInPublic #Java
To view or add a comment, sign in
-
Java forces you to be explicit about 𝐡𝐨𝐰 𝐝𝐚𝐭𝐚 𝐥𝐢𝐯𝐞𝐬 𝐢𝐧 𝐦𝐞𝐦𝐨𝐫𝐲. That’s why primitive types exist. When you use primitives like 𝗶𝗻𝘁, 𝗱𝗼𝘂𝗯𝗹𝗲, or 𝗯𝗼𝗼𝗹𝗲𝗮𝗻, you’re working directly with values — not objects, not references. This matters more than it looks. Primitive types: • Are faster to access • Use less memory • Behave predictably Compare that with objects. Objects live on the heap, come with overhead, and are accessed through references. Early on, this difference feels theoretical. Later, it explains performance issues, memory leaks, and why certain designs don’t scale. Understanding primitives teaches an important habit: 𝗰𝗵𝗼𝗼𝘀𝗲 𝘁𝗵𝗲 𝘀𝗶𝗺𝗽𝗹𝗲𝘀𝘁 𝗿𝗲𝗽𝗿𝗲𝘀𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻 𝘁𝗵𝗮𝘁 𝘀𝗼𝗹𝘃𝗲𝘀 𝘁𝗵𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺. Not everything needs to be an object. Not everything needs abstraction. Today was about: • What primitive data types really are • How they differ from reference types • Why memory awareness matters in Java Good performance doesn’t start with optimization. It starts with understanding fundamentals. #Java #Performance #MemoryManagement #Programming #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 24 of my DSA Journey (LeetCode + Java) Today’s practice focused on Binary Search + HashSet + Two Pointer — three powerful techniques used across many array problems. Each problem became easier once I recognized the correct pattern. ✅ Problems Solved Today: LC 34 – Find First and Last Position of Element in Sorted Array LC 349 – Intersection of Two Arrays LC 167 – Two Sum II (Input Array Is Sorted) 🧠 My Experience Solving These: 🔸 34. Find First and Last Position of Element in Sorted Array At first it looked tricky, but once I understood the pattern, the solution became clear. I used Binary Search twice: First binary search → find the first occurrence Second binary search → find the last occurrence By adjusting left/right pointers based on comparisons, the problem was solved in O(log n) efficiently. 🔸 349. Intersection of Two Arrays A simple and clean problem using HashSet. Store unique elements of first array in a set Check which elements of second array exist in the set Add them to a result set to maintain uniqueness Then convert the result set to an array. Very straightforward and optimal. 🔸 167. Two Sum II – Input Array Is Sorted This was a classic Two Pointer problem. Use left and right pointers Compare their sum with target Move pointers inward based on sum Since the array was sorted, this approach solved the problem in O(n). 📌 Key Takeaway Today: Choosing the right technique makes problem solving much faster. ✔ Binary Search for finding positions ✔ HashSet for uniqueness and fast lookup ✔ Two Pointers for sorted array problems ✔ Always think about the optimal pattern first Every day I’m improving at recognizing patterns and writing cleaner solutions. On to Day 25! 🚀 #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #CodingJourney #Consistency #LearningDaily
To view or add a comment, sign in
-
Our training has officially started, and the first topic we explored was Method Overloading 🔹 Method Overloading Method Overloading is the process of creating multiple methods with the same name inside the same class. ✔ In method overloading, name clashes may happen, but Java resolves them at compile time. ✔ The Java compiler resolves overloading by checking in this order: • Method name • Number of parameters • Data type of parameters • Order of data types 📌 Real-time example: substring() method • Accepts one argument • Also accepts two arguments 🔹 Polymorphism Polymorphism means “one is to many” — a method existing in multiple forms. 📌 Real-time example: Carbon exists in multiple forms that is Carbon dioxide, Coal, Graphite, Diamond and many more ➡ Same element, different forms. 🔹 Virtual Polymorphism Virtual polymorphism is not real polymorphism, but an illusion to the user. 📌 Example: Mobile power button • User thinks one button performs both ON and OFF. In reality, there are two separate methods: • One for power ON and One for power OFF ➡ Hence, it is called virtual (not true) polymorphism 🔹 Method Overloading as Compile-Time Polymorphism ✔ Method calling and method binding happen at compile time ✔ Hence, method overloading is called: • Compile-Time Polymorphism • Early Binding 🔹 Overloading Type Promotion If an exact match is not found, Java: • Looks for the closest possible match • Checks the number of type conversions ⚠ If multiple methods have the same number of conversions, → Ambiguous method call error occurs. 📌 Key Takeaway: Even though we say “one method performs multiple tasks”, 👉 In reality, one method always performs only one task. 💡 Understanding these basics clearly makes advanced Java concepts much easier! Huge Thanks to MALLIKARJUN V VERNEKAR for the guidance. #Java #OOPsConcepts #MethodOverloading #Polymorphism #CompileTimePolymorphism #JavaLearning #ProgrammingBasics 🚀
To view or add a comment, sign in
-
-
🔥 Day 3 / 100 — NeetCode 150 Challenge 📘 Problems Solved: Two Sum & Group Anagrams (LeetCode) 💻 Language: Java Continuing my 100 Days of Coding journey with NeetCode 150, focusing on hashing patterns, efficient lookups, and grouping techniques. 🔹 Problem 1: Two Sum Brute Force Approach I used a nested loop approach to check all possible pairs. The outer loop starts from index 0. The inner loop starts from i + 1 to avoid duplicate checks. If the sum of both elements equals the target, return their indices. Time Complexity: O(n²) Space Complexity: O(1) Optimized Approach — HashMap I used a HashMap to reduce the lookup time. Store each number as the key and its index as the value. For each element, check if target - nums[i] exists in the map. If found, return the stored index and the current index. Time Complexity: O(n) Space Complexity: O(n) 🔹 Problem 2: Group Anagrams HashMap + Frequency Array Approach I grouped strings by building a character frequency signature for each word. For every string, create an integer array of size 26. Count character frequencies using count[c - 'a']++. Convert the frequency array into a string and use it as the hashmap key. If the key already exists, add the string to the existing list. Otherwise, create a new list and insert it into the map. After processing all strings, return the hashmap values as a list of lists. Time Complexity: O(n · k) (n = number of strings, k = max length of a string) Space Complexity: O(n) ✨ Solving Two Sum and Group Anagrams reinforced how powerful hashing can be for optimizing search and grouping problems. On to Day 4 — building momentum, one problem at a time! 🚀 #100DaysOfCode #NeetCode150 #TwoSum #GroupAnagrams #LeetCode #Java #DSA #ProblemSolving
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 9 of sharing what I’ve learned🚀 Type Casting in Java Type casting is the process of converting a value from one data type to another. In Java, type casting is mainly of two types: 🔹 Implicit Casting (Widening Conversion) Converts a smaller data type to a larger data type Done automatically by the Java compiler No data loss / no precision loss Order of Implicit Casting (Primitives): byte → short → int → long → float → double char → int → long → float → double Example: byte a = 45; double b = a; Why this works? byte uses 1 byte double uses 8 bytes A smaller value easily fits into a larger container ✔ Safe conversion ✔ No explicit syntax required 🔹 Explicit Casting (Narrowing Conversion) Converts a larger data type to a smaller data type Must be done manually by the programmer May cause data loss Example (without casting – ❌ error): double a = 45.5; byte b = a; // Compilation error Correct way (with casting): double a = 45.5; byte b = (byte) a; What happens here? double → byte Decimal part (.5) is discarded Final value of b = 45 ⚠ Possible loss of precision ⚠ Risk of overflow for large values 🔑 Key Takeaways Implicit casting is safe and automatic Explicit casting is manual and risky Always be cautious when narrowing data types Java prioritizes type safety over convenience More coming soon. ✨ #Programming #ComputerScience #SoftwareDevelopment #Developers #Coding #Tech #Engineering #Binary #CPU #Microprocessors #SoftwareEngineer #CSFundamentals #Day9 TAP Academy Sharath R
To view or add a comment, sign in
-
-
Day 13 ( DSA using Java) To strengthen my foundation in Data Structures and Algorithms, I’m committing to solving and sharing LeetCode problem in regular periods of time, along with my thought process and approach. Writing it out helps me learn better and opens the door to meaningful discussion. 🔹 Problem: merge Alternately 🔹 Core Concept: strings ,basics solution : public class StringLC { public static String mergeAlternately(String word1, String word2) { StringBuilder sb = new StringBuilder(); int n = word1.length()-1; int m = word2.length()-1; int i=0; int j=0; while(i<=n || j<=m){ if(i<=n && j<=m){ sb.append(word1.charAt(i)); i++; sb.append(word2.charAt(j)); j++; } else if(i<=n){ sb.append(word1.charAt(i)); i++; } else{ sb.append(word2.charAt(j)); j++; } } return sb.toString(); } public static void main(String[] args) { System.out.println(mergeAlternately("abc", "pqrs")); } } I’ve included my solution and time–space complexity analysis. I’d love to hear how others approached this problem—were there alternative or more efficient strategies? Let’s learn, improve, and grow together. **#LeetCode** **#DSA** **#ProblemSolving** **#CodingJourney** **#SoftwareEngineering** **#LearningInPublic** **#Java**
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