🚀 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
Mastering Java with LeetCode: Problem Solved - 1657
More Relevant Posts
-
Today I explored some fundamental yet powerful concepts in Java that every developer should have a strong grip on: 🔹 Static Methods & VariablesUnderstanding how static members are shared across all objects really changed how I think about memory and efficiency. It’s amazing how a simple static keyword can help track object creation and maintain shared data seamlessly. 🔹 Constructor Overloading & this KeywordThis concept made object initialization much more flexible. Using multiple constructors and the this keyword not only improves code readability but also avoids redundancy. 💡 What I realized:Strong basics are the real game-changer. These concepts might look simple, but they build the foundation for writing clean, scalable, and efficient code. 📌 Consistency in learning > Complexity in topics I’m currently focusing on strengthening my core Java skills and building projects around them. Every small concept learned today contributes to becoming a better developer tomorrow. #Java #Programming #CodingJourney #DeveloperLife #JavaDeveloper #Learning #TechSkills #Coding #StudentDeveloper
To view or add a comment, sign in
-
🚀 Mastering Time & Space Complexity in Java DSA When I started learning Data Structures & Algorithms in Java, the biggest mindset shift wasn’t coding… it was thinking in complexity. 📌 Time Complexity (⏱️) It tells how fast your code runs as input grows. O(1) → Constant (Best 👍) O(log n) → Logarithmic O(n) → Linear O(n log n) → Efficient sorting O(n²) → Slow (avoid when possible ⚠️) 📌 Space Complexity (💾) It tells how much memory your code uses. Efficient programs don’t just run fast — they also use less memory. 💡 Key Learnings: ✔️ Always analyze before optimizing ✔️ Nested loops ≠ always bad, but be careful ✔️ Trade-offs exist between time & space ✔️ Practice problems to build intuition 🔥 Current Focus: Improving problem-solving by writing optimized Java solutions and analyzing their complexity. Consistency > Motivation 💯 #Java #DSA #CodingJourney #TimeComplexity #SpaceComplexity #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 89 ✅ Today, I solved the Minimum Distance to the Target Element problem on LeetCode 💻 🔍 Problem Insight: Given an array, a target element, and a starting index — we need to find the minimum distance between the start index and any occurrence of the target. 🧠 Approach I Used: Traversed the array using a loop Checked where the element equals the target Calculated distance using Math.abs(i - start) Updated the minimum distance using Math.min() ⚡ Key Learning: Sometimes the simplest linear traversal (O(n)) gives the most optimal solution. No need to overcomplicate! 💡 Code Concept: Use a variable to track minimum distance Update it whenever a closer target is found 💬 What I Learned Today: Consistency is more important than complexity. Even simple problems strengthen your fundamentals! 🔥 Day 89 Progress: Strengthened problem-solving skills Improved understanding of distance-based logic Practiced writing clean and optimized Java code 📈 Still learning, still growing… one problem at a time! #LeetCode #DSAinJava #ProblemSolving #Java #CodingJourney #Consistency #SoftwareDeveloper 🚀
To view or add a comment, sign in
-
-
🚀 **Day 10 of My DSA Journey in Java** Today’s focus was on one of the most powerful concepts in programming — **Loops** 🔁 Loops help us run a block of code multiple times, making programs more efficient, compact, and easier to debug. Here’s what I learned: 🔹 **For Loop** Understood its structure — initialization, condition, and update — and how it controls iterations. 🔹 **Nested Loops** Learned how to use loops inside loops, especially for solving pattern-based problems like star patterns ⭐ 🔹 **Jump Statements** `break` → Immediately exits the loop `continue` → Skips the current iteration and moves to the next 🔹 **While Loop** Executes as long as the condition remains true. 🔹 **Do-While Loop** Runs at least once, even if the condition is false — a unique and useful behavior. 💡 **Key Takeaway:** Loops are essential for writing efficient code and solving repetitive problems with ease. #Java #DSA #LearningInPublic #Programming #100DaysOfCode #JavaDeveloper
To view or add a comment, sign in
-
🚀 **Day 4 of My DSA Journey in Java** Today, I took my first real step into writing Java programs and understanding how code actually works behind the scenes. 🔹 Learned about **functions/methods** — reusable blocks of code designed to perform specific tasks, along with the concept of input and output. 🔹 Understood the importance of the **main() function** — the entry point where every Java program begins execution. 🔹 Wrote my first **Hello World program** using `System.out.println()` 🎉 🔹 Explored the difference between `print` and `println` for output formatting. 🔹 Learned how to use **comments** (`//` and `/* */`) to make code more readable and maintainable. 🔹 Got introduced to the structure of classical Java syntax like `public static void main`. One key takeaway: not everything needs to be mastered instantly — some concepts are okay to understand at a basic level now and explore deeply later. Slowly building consistency and strengthening my fundamentals 💻✨ #DSA #Java #LearningJourney #Coding #Programming #Beginners #Consistency
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 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
-
-
Day 16 of My Java Learning Journey Today, I explored an efficient and elegant approach to finding the median of a list using Java Streams. Instead of relying on traditional iterative logic, this solution leverages the power of functional programming to: • Sort the dataset • Dynamically identify the middle element(s) • Handle both odd and even-sized lists seamlessly • Compute the result using a concise and readable pipeline What makes this approach impactful is not just correctness, but clarity. With a few well-structured stream operations, we can express a problem that typically requires multiple conditional checks in a much cleaner way. This reinforces an important principle in modern Java development: writing code that is not only efficient, but also expressive and maintainable. Consistently practicing these patterns is helping me think in terms of data transformations rather than step-by-step instructions — a key mindset shift for building scalable applications. #Java #JavaStreams #FunctionalProgramming #CodingJourney #SoftwareDevelopment #CleanCode #Programming #Developers #TechLearning #BackendDevelopment #CodeDaily #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 8 – Understanding Functions and Parameters in Java Today, I learned about functions (methods) in Java, which are very important for writing clean and reusable code. A function is simply a block of code that performs a specific task and can be used multiple times in a program. This helps to reduce repetition and makes the code easier to understand. I started by learning the basic syntax of a function, where we define a return type, function name, and body. Then I moved to functions with parameters, where values are passed into the function to perform operations. This made the concept more practical. Next, I learned about types of parameters: Formal Parameters: These are variables defined in the function. Actual Parameters: These are the values passed when calling the function. 👉 Understanding this difference made it clear how data flows inside a program. Overall, today’s learning helped me understand how to write better and more structured code using functions. 💪 I will keep practicing daily and improve step by step in my coding journey. #Java #Coding #DSA #Learning #Consistency
To view or add a comment, sign in
-
-
Understanding Polymorphism in Java can be challenging, but simplifying it can make a big difference. Polymorphism means “one thing, many forms.” In Java, it primarily occurs in two ways: 1. Method Overloading (Compile-time Polymorphism) - Same method name, different parameters - Example: - add(int a, int b) - add(int a, int b, int c) 2. Method Overriding (Runtime Polymorphism) - A subclass provides its own implementation of a method - Example: - A Vehicle class has a method start() - A Car class overrides it with its own logic Why is this powerful? - It makes code flexible - It improves reusability - It helps write cleaner programs A simple way to remember: - Overloading = Same method, different inputs - Overriding = Same method, different behavior I wish I had learned it this way earlier—it would have saved me hours! If you're learning Java, keep going. Consistency beats complexity. #Java #Programming #Coding #OOP #Learning #Developers
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