🚀 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
Mastering Java with LeetCode Equal Row and Column Pairs Problem
More Relevant Posts
-
🚀 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 32 Today I solved an Easy-level Tree problem that strengthened my understanding of Recursion + Depth Calculation — a fundamental concept for tree-based problems 📌 LeetCode Problem Solved: Q.104. Maximum Depth of Binary Tree 💭 Problem Summary: Given a binary tree, the task is to find the maximum depth — i.e., the number of nodes along the longest path from root to leaf. 🧠 Approach (Optimal): Instead of iterating level by level, I used a clean recursive approach: ✔️ If node is null → return 0 ✔️ Recursively calculate left subtree depth ✔️ Recursively calculate right subtree depth ✔️ Return 1 + max(left, right) ⚡ Key Learning: Recursion makes tree problems much simpler when you think in terms of “what should each function return for a node?” Complexity: Time: O(n) Space: O(h) Takeaway: Tree problems become easier once you master recursion and start recognizing patterns. Consistency is the key — showing up every day #Day32 #LeetCode #Java #DSA #CodingJourney #Recursion #BinaryTree #100DaysOfCode #SoftwareEngineering
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
-
-
🚀 Just solved LeetCode's Palindrome Number problem in Java — and all 11,511 test cases passed! ✅ Here's what I learned building a clean, string-based solution: 💡 The Approach: → Convert the integer to a string → Reverse it character by character → Compare the original vs reversed string Simple? Yes. But the real win is in the edge case — returning false immediately for negative numbers. That's clean defensive programming. 🧵 Key Takeaway: You don't always need complex math. Sometimes the most readable solution is the best solution — and readability is what makes code maintainable in production. ⚡ Runtime: 16ms | Memory: 46.62MB Not the fastest (beats 5.61%), but it's clear, correct, and gets the job done. I'm challenging myself to solve problems daily and document my thinking. Consistency > perfection. If you're on a similar DSA journey, let's connect! Drop your approach in the comments — I'd love to see how others tackled this. 👇 #LeetCode #Java #DSA #DataStructures #CodingChallenge #ProblemSolving #SoftwareDevelopment #100DaysOfCode #TechIndia
To view or add a comment, sign in
-
-
Day 98 - LeetCode Journey Solved LeetCode 20: Valid Parentheses in Java ✅ A classic stack problem that looks simple but tests your attention to detail. The idea is straightforward: Push opening brackets into stack and match them correctly when a closing bracket appears. If anything mismatches → invalid. Clean logic, zero confusion 💡 Key takeaways: • Stack fundamentals • Matching pairs efficiently • Handling edge cases (empty stack, wrong order) • Writing clean conditional logic ✅ All test cases passed ⚡ O(n) time and O(n) space Sometimes basics like this are the real building blocks of strong DSA 🔥 #LeetCode #DSA #Java #Stack #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
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
-
-
🚀 **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
-
Today I worked on a problem that involved finding the maximum count of positive and negative numbers in a sorted array. Key idea: Used Binary Search to efficiently find: The first positive number The first non-negative number From this, we can calculate: Count of positive numbers Count of negative numbers Why Binary Search? Because the array is sorted, it helps reduce time complexity to O(log n) instead of scanning the entire array. What I learned: How to apply binary search beyond just finding elements How to think in terms of boundaries (first occurrence logic) Writing clean and optimized Java code 📌 Problem-solving is not just about coding, it's about thinking efficiently. Looking forward to learning more and improving every day! #Java #DSA #BinarySearch #CodingJourney #ProblemSolving #LearningEveryday
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
-
-
Debugged & Optimized: Beats 100% on LeetCode! 🚀 By switching to a Two-Pass O(n) logic in Java, I was able to find all valid elements while beating 100% of submissions in speed. Key Takeaway: Debugging is just as important as coding. Sticking with the problem until the logic is optimal is where the real learning happens. Onwards to more complex challenges! #Java #DSA #LeetCode #ProblemSolving #Engineering
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