🚀 Mastering Java Through LeetCode 🧠 Day 23 of My DSA Journey Today I solved an interesting stack-based problem that improved my understanding of string manipulation and data structures. 📌 LeetCode Problem Solved Today: Q. 2390 – Removing Stars From a String 💡 Problem Statement: Given a string containing *, remove each star along with the closest non-star character to its left. Approach: I used a Stack-based approach: Traverse the string character by character If the character is not *, push it into the stack If the character is *, pop the top element from the stack Finally, build the result string from the stack ✨ This approach works efficiently in O(n) time and ensures all operations are handled correctly. 📈 Key Learnings: Stack helps in handling last-in-first-out (LIFO) operations Efficient string manipulation using StringBuilder Importance of choosing the right data structure 🔥 Consistency is key — improving problem-solving skills every day! #Java #DSA #LeetCode #CodingJourney #SoftwareDevelopment #ProblemSolving #Tech #Learning #Developers #OpenToWork #CAC
Mastering Java with LeetCode Stack Problem Solution
More Relevant Posts
-
🚀 Mastering Java Through LeetCode Day 19 Today I solved an interesting problem that helped me strengthen my understanding of Hashing and Data Structures. 📌 LeetCode Q. 2215 – Find the Difference of Two Arrays 🔍 Problem Insight: Given two arrays, the task is to find: ✔️ Elements present in nums1 but NOT in nums2 ✔️ Elements present in nums2 but NOT in nums1 👉 And return only distinct values 💡 Approach I Used: Used HashMap to store unique elements Checked presence using containsKey() (O(1) lookup) Built two result lists efficiently Why this approach? Hashing reduces time complexity and avoids duplicate handling manually. Key Learning: Sometimes choosing the right data structure (HashMap/HashSet) makes the solution clean, fast, and interview-ready. Complexity: Time: O(n + m) Space: O(n + m) Pro Tip: Using HashSet can make the solution even more optimized and readable. Consistency is not about perfection, it's about showing up every day and improving 1% #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Programming #SoftwareEngineer #Coding #Developers #HashMap #Learning #Tech #PlacementPreparation #CDAC #OpenToWork
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 22 of My DSA Journey Today I solved an interesting matrix-based problem that improved my understanding of arrays and comparison logic. 📌 LeetCode Problem Solved Today: 2352 – Equal Row and Column Pairs Problem Statement: Given an n x n matrix, find how many pairs (row, column) are exactly the same. A pair is valid only if both contain the same elements in the same order. 🧠 Key Idea: Compare each row with every column Check element-by-element equality Count all matching pairs 🔍 Example: Input: [[3,2,1], [1,7,6], [2,7,7]] Output: 1 Matching Pair: Row 2 = Column 1 → [2,7,7] ⚙️ Approach: Traverse all rows Build each column dynamically Compare row[i][k] with column[k][j] If all elements match → increment count ⏱️ Time Complexity: O(n³) (Optimized solution using HashMap possible in O(n²)) What I Learned: Matrix traversal techniques Row vs Column comparison logic Importance of nested loops in grid problems 🔥 Consistency is the key! Every day one problem closer to my goal of becoming a Software Engineer #LeetCode #DSA #Java #CodingJourney #100DaysOfCode #SoftwareEngineer #ProblemSolving #Learning #Tech
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 20 of My DSA Journey Today I solved another problem from the LeetCode 75 list to improve my understanding of HashMap and HashSet concepts and strengthen my problem-solving skills. 📌 LeetCode Problem Solved Today: Q.1207 – Unique Number of Occurrences 💡 Problem Statement: Given an integer array arr, return true if the number of occurrences of each value in the array is unique, otherwise return false. 🧩 Example 1: Input: [1,2,2,1,1,3] Output: true 🧩 Example 2: Input: [1,2] Output: false Key Learning: Today I learned how to efficiently solve problems using Hashing techniques: ✔️ Use HashMap to count frequency of each number ✔️ Use HashSet to check if frequencies are unique ✔️ If any frequency repeats → return false 🧠 Approach: 1️⃣ Traverse array and store frequency using getOrDefault() 2️⃣ Traverse map values 3️⃣ Check duplicates using HashSet ⏱️ Complexity: Time Complexity: O(n) Space Complexity: O(n) This problem helped me understand how frequency counting + uniqueness checking works in real interview scenarios. Consistency is the key — solving problems daily to become a better software engineer 💻 #LeetCode #Java #DSA #ProblemSolving #CodingJourney #LearningInPublic #SoftwareDevelopment #Programming #Coding #Tech #Developers #100DaysOfCode #TechCareer #InterviewPreparation #HashMap #HashSet #CodingPractice #PGCP #CDAC #LeetCode75
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 33 Not all nodes are “Good”… but finding them made me better at Trees 📌 LeetCode Problem Solved: Q.1448 – Count Good Nodes in Binary Tree 💭 Problem Summary: A node is called “Good” if no node on the path from root to it has a greater value. 🎯 Approach: ✔ Used DFS (Depth First Search) ✔ Tracked the maximum value seen so far in the path ✔ If current node ≥ maxSoFar → count it as a Good Node ✔ Updated max and continued recursion 🧠 Key Insight: Instead of storing the full path, just carry maxSoFar — simple yet powerful optimization! 💡 Complexity: ⏱ Time: O(N) 📦 Space: O(H) 🔥 What I Learned: How to maintain state during recursion Clean way to solve tree problems using DFS Thinking in terms of path-based conditions Consistency builds confidence 💪 Day 33 done… Let’s keep going 🚀 #Java #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #DSA #Tech #Learning
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 17 of My DSA Journey Today I solved another problem from the LeetCode list to improve my understanding of arrays and prefix sum concepts. 📌 LeetCode Problem Solved Today: Q.1732. Find the Highest Altitude In this problem, a biker starts a road trip from altitude 0, and we are given an array that represents the gain or loss in altitude between points. The task is to find the highest altitude reached during the trip. Method 1: Using ArrayList (My 1st Approach) I stored all altitudes step by step in an ArrayList and then used Collections.max() to find the highest altitude. Method 2: Optimized Approach (My Second Approach Without Extra Space) Instead of storing all values, we can directly track the maximum altitude while iterating. 💻 Optimized Java Solution class Solution { public int largestAltitude(int[] gain) { int altitude = 0; int maxAltitude = 0; for (int g : gain) { altitude += g; maxAltitude = Math.max(maxAltitude, altitude); } return maxAltitude; } } Example: Input: gain = [-5,1,5,0,-7] Altitudes formed: [0, -5, -4, 1, 1, -6] Highest altitude = 1 Consistent practice is helping me strengthen my DSA and problem-solving skills step by step. #LeetCode #DSA #Java #CodingJourney #ProblemSolving #ArrayList #100DaysOfCode #SPPU #EngineeringLife #TechCommunity #CDAC
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 21 of My DSA Journey 📌 Problem Solved: Q.1657 – Determine if Two Strings Are Close 💡 Problem Insight: At first glance, this problem looks like a simple string comparison… But it actually tests your understanding of patterns, hashing, and transformations. We are allowed to: ✔ Swap characters (change order) ✔ Transform characters (swap frequencies) 🧠 Key Learning: Two strings are "close" if: ✅ They have the same set of characters ✅ Their frequency distribution matches (order doesn’t matter) 👉 That means: Order is irrelevant Only character presence + frequency pattern matters 🔍 Approach I Used: 1️⃣ Checked if lengths are equal 2️⃣ Counted frequency using arrays 3️⃣ Verified both strings have same unique characters 4️⃣ Sorted frequency arrays and compared ⚡ Example: word1 = "cabbba" word2 = "abbccc" ✔ Same characters → {a, b, c} ✔ Frequencies match after sorting → [1,2,3] 👉 Result: true Tech Stack: Java Concepts Covered: Hashing | Arrays | Frequency Count Takeaway: This problem taught me how to: Think beyond direct comparison Focus on data patterns instead of structure Consistency + Practice = Growth #LeetCode #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving #Developers #SoftwareEngineer #Learning #Growth #CDAC #PlacementPreparation #Tech
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 28 Today I solved an interesting Medium-level problem that strengthens understanding of Linked Lists & Two Pointer Technique 💡 📌 LeetCode Problem Solved Today: Q.2095 Delete the Middle Node of a Linked List 🔍 Problem Summary: Given the head of a linked list, the task is to delete the middle node and return the modified list. The middle is calculated using 0-based indexing (⌊n/2⌋). ⚡ Approach Used: I used the Slow & Fast Pointer technique: Slow pointer moves 1 step at a time Fast pointer moves 2 steps When fast reaches the end, slow points to the middle node Then we simply remove that node by adjusting pointers. 💻 Key Learning: Efficient traversal without counting nodes Importance of pointer manipulation in Linked Lists Handling edge cases (like single node) 📈 Consistency is the key! Improving problem-solving skills one day at a time 💪 #leetcode #dsa #java #linkedlist #coding #programming #softwareengineering #developers #codingchallenge #100daysofcode #tech #interviewpreparation #computerscience #codingjourney #learning #growth #motivation #placements #fresherjobs
To view or add a comment, sign in
-
-
Day 38 – 44 of my Frontlines EduTech (FLM) AI-Powered Java Full Stack Journey Day 38: Started learning Collections in Java. Focused on ArrayList and how it stores dynamic data. Understood how it is different from arrays. Day 39: Learned about Iterator. Used it to traverse elements in collections. It made looping through data more clean and flexible. Day 40: Explored Set interface. Learned that it stores only unique elements. Good for removing duplicates from data. Day 41: Learned Map in Java. Stores data in key-value pairs. Very useful for real-world applications. Day 42: Covered Enum and Command Line Arguments. Also learned Static and Instance Blocks. Understood when and how they are executed. Day 43: Learned Clone, Comparator, and Comparable. Used for copying objects and sorting data. Important for customizing sorting logic. Day 44: Solved problem on frequency of characters. Used logic with collections to count occurrences. Good practice for improving problem-solving skills. Consistent learning, step by step. Fayaz S 🔗 Github: https://lnkd.in/gV_uis3J #Java #Collections #CodingJourney #100DaysOfCode #LearnJava #FullStack 🚀
To view or add a comment, sign in
-
-
Day 10 of Java DSA Journey 🚀 📌 Problem: Power of Two (LeetCode 231) Most people solve this using loops: ➡️ Keep dividing by 2 until you reach 1 But today I learned something better: 👉 You can solve it in ONE line using bit manipulation 🤯 💡 Core Idea A number is a power of two if: ✔️ It has only one ‘1’ in its binary form Examples: 1 → 0001 2 → 0010 4 → 0100 16 → 10000 🧠 The Magic Trick 👉 n & (n - 1) This removes the rightmost set bit So: If result = 0 → only one bit was set → ✅ Power of Two Else → ❌ Not a power of two ⚡ Complexity ⏱ Time: O(1) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Always Check Positivity First n > 0 is mandatory — bit tricks fail for negative numbers. 💡 Tip 2: Understand, Don’t Memorize n - 1 flips: the rightmost 1 → 0 all bits after it → 1 That’s why the trick works. 💡 Tip 3: This Pattern Appears Everywhere The same trick is used in: Counting set bits Subset generation Low-level optimizations 👉 Learn it once, reuse forever. 💡 Tip 4: Alternative Trick (Even Cleaner) Another way: 👉 (n & -n) == n This isolates the lowest set bit. If it's equal to n, only one bit exists. 💡 Tip 5: Bitwise = Senior-Level Thinking Using bit manipulation shows: ✔️ You understand how data is stored ✔️ You can optimize beyond brute force 🔥 Real Insight This problem is not about checking powers… It’s about recognizing: 👉 Patterns in binary representation Once you see that, the solution becomes obvious. Consistency builds mastery 🔑 #DSA #LeetCode #Java #BitManipulation #CodingJourney #ProblemSolving #InterviewPrep #Day10 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Java Full Stack Development Journey | Day 13 Today, I focused on understanding Inheritance and Polymorphism in Java — key concepts that help in writing reusable, scalable, and flexible code. 🔑 Key Concepts I Explored: 🔹 Inheritance Allows one class to acquire properties and behaviors of another class using extends, promoting code reusability. 🔹 Types of Inheritance Learned about Single, Multilevel, and Hierarchical inheritance in Java. 🔹 Method Overriding Redefining a parent class method in a child class to provide a specific implementation. 🔹 Polymorphism One interface, multiple forms — achieved through method overloading (compile-time) and method overriding (runtime). 💡 Simple Example: class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } } public class Main { public static void main(String[] args) { Animal obj = new Dog(); // Polymorphism obj.sound(); } } 📌 Key Learning: Inheritance helps in reducing code duplication, while polymorphism increases flexibility and maintainability in applications. #Java #JavaDeveloper #FullStackDevelopment #JavaFullStack #Programming #CodingJourney #LearningJava #SoftwareDevelopment #OOP #DeveloperLife #TechLearning #Inheritance #ObjectOrientedProgramming #Polymorphism #Coding
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