At first, the Rotate Image problem looked tricky. Rotating a matrix in-place isn’t something that feels obvious right away. But after thinking about it, I realized it’s not about rotation directly, it’s about transforming the matrix step by step. By first flipping it across the diagonal (transpose) and then reversing each row, the rotation happens naturally. Moments like this remind me that in coding, the right approach often matters more than the problem itself. Learning to break problems down is the real skill. RAVI KUMAR Coding Blocks Sunstone #Coding #DSA #Java #ProblemSolving #GrowthMindset #Learning
Rotating Matrix in-Place with Transpose and Reverse
More Relevant Posts
-
Day 55 of 100 Days of LeetCode 💻 Today I solved Longest Consecutive Sequence — and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the “start of sequence” logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). 💡 Lesson learned: Don’t just think your logic is right → verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ✅ Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
To view or add a comment, sign in
-
-
🚀 Solved LeetCode Problem #58 – Length of Last Word Today I worked on a simple yet insightful string manipulation problem that emphasizes attention to edge cases. 🔍 Problem Insight: Given a string containing words and spaces, the goal is to find the length of the last word, ignoring any trailing spaces. 💡 Approach Used: Instead of using built-in methods like split(), I implemented an optimized approach by: Traversing the string from the end Skipping trailing spaces Counting characters until the next space is encountered This approach avoids extra space usage and improves efficiency. 🧠 Key Learning: Importance of handling edge cases like trailing spaces How reverse traversal can simplify string problems Writing memory-efficient solutions 📈 Complexity: Time: O(n) Space: O(1) ✨ Problems like this help strengthen: String manipulation skills Logical thinking Writing clean and optimized code Consistency is key—one step closer to mastering DSA! 💪 #LeetCode #DSA #StringManipulation #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 17 of LeetCode Problem Solving Solved today’s problem — LeetCode #13: Roman to Integer 💻🔥 ✅ Approach: Traversal + Mapping ⚡ Time Complexity: O(n) 📊 Space Complexity: O(1) The task was to convert a Roman numeral string into an integer. 👉 I mapped each Roman symbol to its value and traversed the string to calculate the result. 💡 Key Idea: If current value < next value → subtract it Otherwise → add it 👉 Core Logic: Convert each character to its numeric value Compare with next character Apply addition or subtraction accordingly 💡 Key Learning: Understanding patterns (like subtraction rule in Roman numbers) helps simplify the problem logic. Consistency is the key — improving step by step 🚀 #Day17 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 10 of #100DaysOfDSA – Solved LeetCode 344: Reverse String Today’s problem was simple yet powerful — Reverse a String (in-place) 💡 🔹 Problem: Given a character array, reverse it without using extra space. 🔹 Approach: Used the Two Pointer Technique: 👉 Start one pointer from the beginning 👉 Another from the end 👉 Swap characters and move inward 🔹 Key Learning: In-place operations improve space efficiency Two-pointer approach is a must-know pattern for interviews 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) 💻 Code Insight: Swapping elements until both pointers meet does the job efficiently! ✨ Small problems like this build strong fundamentals for bigger challenges. #DSA #Java #Coding #LeetCode #Programming #SoftwareEngineering #InterviewPrep #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 8 of 30 Days Coding Challenge Today I solved a problem on LeetCode: Minimum Distance Between Three Equal Elements. 🔍 Approach: Initially implemented a brute-force solution using three nested loops (O(n³)). It worked for smaller constraints but highlighted the importance of optimizing. 💡 Key Learning: Instead of checking all possible triplets, grouping indices of identical elements and analyzing consecutive occurrences leads to a much more efficient solution. ⚡ Optimization Insight: Reduced time complexity from O(n³) → O(n) Leveraged HashMap to store indices and process only relevant combinations. 📈 Takeaway: This problem reinforced an important concept: 👉 When dealing with repeated elements, think in terms of grouping and patterns rather than brute force. Consistency is key — learning something new every day and improving step by step. #Day8 #30DaysOfCode #CodingChallenge #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnToCode #TechGrowth
To view or add a comment, sign in
-
-
Day 8/30 of my #30DaysDSAChallenge 🚀 Solved Problem 70 on LeetCode: Climbing Stairs 🧗♂️ At first glance, it looks simple — but the real learning was in identifying the pattern. This problem is a classic example of how Dynamic Programming works behind the scenes. 💡 Key Insight: To reach step n, you can either come from n-1 or n-2. Which leads to a Fibonacci-like relation: 👉 ways(n) = ways(n-1) + ways(n-2) Instead of using recursion (which is inefficient), I implemented an optimized iterative approach with O(n) time and O(1) space. 📚 What I learned today: Recognizing DP patterns in problems Converting recursion → optimized iteration Importance of space optimization Small steps every day, but getting stronger with problem-solving 💪 #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 54 – 100 Days Coding Challenge 📌 Problem: Three Sum ⚙️ Approach • First, sort the array to make it easier to apply the two-pointer technique • Iterate through the array and fix one element at a time • For each fixed element, use two pointers (left and right) to find pairs whose sum equals the negative of the fixed element • Skip duplicate elements to avoid repeating triplets • Move pointers based on the sum: – If sum == 0 → store the triplet and move both pointers – If sum < 0 → move left pointer forward – If sum > 0 → move right pointer backward 🧠 Logic Used • Sorting + Two Pointer Technique • Handling duplicates efficiently to ensure unique triplets • Reducing time complexity from brute force O(n³) to O(n²) 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 54 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #TwoPointers #ArrayProblems
To view or add a comment, sign in
-
-
🚀 Day 11/100 — #100DaysOfLeetCode Consistency continues — one problem closer to better problem-solving skills 💻🔥 ✅ Problem Solved: 🔹 LeetCode 1423 — Maximum Points You Can Obtain from Cards 💡 Concepts Used: Sliding Window Technique Complementary Subarray Thinking 🧠 Key Learning: Instead of directly choosing k cards from both ends, I learned to think differently — find the minimum sum subarray of size n - k and subtract it from the total sum. This transformation converts a complex decision problem into a clean sliding window optimization. ⚡ Takeaway: Sometimes optimization comes from changing perspective, not increasing complexity. Continuing the journey 🚀 #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Solved: Count Number of Factors of N (DSA) Today I worked on a classic problem — finding the number of divisors of a number. 🔹 Started with a basic approach: O(N) 🔹 Optimized it to: O(√N) using divisor pairs 💡 Key Insight: Every divisor i has a corresponding pair N/i, which helps reduce the number of iterations significantly. Also handled the edge case of perfect squares carefully ✔️ This is a small problem, but it builds strong fundamentals for: Number Theory Competitive Programming Technical Interviews Would love feedback from the community 🙌 #DSA #Java #Coding #ProblemSolving #SoftwareEngineering #LearningInPublic
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