Day 2/100 – LeetCode Challenge 🚀 Problem: #48 Rotate Image Difficulty: Medium Language: Java Approach: In-Place Rotation using Transpose + Row Reversal Time Complexity: O(n²) Space Complexity: O(1) 🔍 Key Insight: To rotate a matrix 90° clockwise without extra space: 1️⃣ First transpose the matrix (swap across diagonal). 2️⃣ Then reverse each row. This avoids creating a new matrix and satisfies the in-place constraint. 🧠 Solution Brief: Used nested loops to transpose the matrix by swapping arr[i][j] and arr[j][i]. Then reversed each row using two pointers (start and end). Combined both operations inside a rotate() method. Achieved full rotation with constant extra space. 📌 What I Learned: Matrix problems are more about pattern recognition than brute force. Understanding transformations (transpose + reverse) makes complex problems simple. Starting my 100 Days of LeetCode journey today 💪 Consistency > Motivation. #LeetCode #Day2 #100DaysOfCode #Java #DSA #Matrix #ProblemSolving #CodingJourney #MediumProblem
LeetCode Challenge Day 2: Rotate Image in Java
More Relevant Posts
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 536 of #750DaysOfCode 🚀 Today I solved Count Submatrices With Equal Frequency of X and Y (LeetCode 3212) using Java. 🔹 Problem Summary: Given a grid containing 'X', 'Y', and '.', we need to count the number of submatrices starting from the top-left corner (0,0) such that: • The number of 'X' and 'Y' is equal • The submatrix contains at least one 'X' 🔹 Approach: Instead of checking every possible submatrix (which would be too slow), I used the Prefix Sum technique. I maintained two prefix matrices to store the count of 'X' and 'Y' up to each cell. For every position (i, j), I checked: countX == countY and countX > 0 If true, that submatrix is valid. This reduces the complexity to O(n × m), which works efficiently for large grids. 🔹 Key Concepts Learned: ✅ Prefix Sum in 2D ✅ Matrix traversal optimization ✅ Handling constraints up to 1000 × 1000 ✅ Clean implementation in Java Consistent practice is making problem-solving faster and more structured every day. #750DaysOfCode #Day536 #LeetCode #Java #DataStructures #Algorithms #PrefixSum #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
Day 55 of #100DaysOfLeetCode 💻✅ Solved #434. Number of Segments in a String problem in Java. Approach: • Initialized a counter to track number of words (segments) • Traversed the string character by character • Checked for non-space characters • If the current character is not a space and either it is the first character or the previous character is a space, incremented the count • This ensures counting only the starting of each word Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.83 MB (Beats 99.81% submissions) Key Learning: ✓ Practiced string traversal without using extra space ✓ Learned how to identify word boundaries efficiently ✓ Improved logic building for handling spaces and edge cases Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 2 of my #365DaysCodingChallenge | CodeOjas Journey Today, I solved 3 interesting array-based problems using Java: 🔹 Unique Subarray Sum Pairs – Found pairs of subarrays with equal sums using hashing techniques. 🔹 Array Rotation – Rotated array efficiently using optimized reversal approach. 🔹 Shifted Array – Implemented element shifting with proper handling of wrap-around using modular arithmetic. 💡 Approach: Focused on breaking problems into smaller parts, using concepts like subarrays, indexing, and optimization techniques. ⚡ Complexity: Most solutions were optimized to O(n) time with minimal space. 📌 Takeaway: Strong understanding of array manipulation and problem breakdown is key to solving DSA problems efficiently. Building consistency and improving every day 💪🔥 📂 Code: [Your GitHub Link] #DSA #Java #CodeOjas #365DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
Day 6/100 – LeetCode Challenge 🚀 Problem: #189 Rotate Array Difficulty: Medium Language: Java Approach: Array Reversal Technique Time Complexity: O(n) Space Complexity: O(1) 🔍 Key Insight: Instead of shifting elements one by one, the array can be rotated efficiently using a three-step reversal strategy. Steps: 1️⃣ Reverse the entire array 2️⃣ Reverse the first k elements 3️⃣ Reverse the remaining elements This achieves the required rotation in-place with constant extra space. 🧠 Solution Brief: Calculated k % n to handle cases where k is greater than array length. Reversed the entire array first. Then reversed the first k elements and the remaining n-k elements. This sequence correctly rotates the array to the right. 📌 What I Learned: Understanding patterns like array reversal can simplify problems that initially seem complex. Optimizing from brute force shifting to an in-place O(n) solution improves efficiency. #LeetCode #Day6 #100DaysOfCode #Java #DSA #Arrays #RotateArray #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Leetcode Problem || Number of Steps to Reduce a Number in Binary Representation to One(1404)🚀 Today I solved a binary manipulation problem where we must: If number is even → divide by 2 If odd → add 1 Count steps until number becomes 1 💡 Learned: How to simulate binary addition using carry Avoid integer overflow Optimize string-based numeric problems #Java #DSA #BitManipulation #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Leetcode Problem || Sort Integers by Number of 1 Bits (1356)🚀 Today I worked on a problem where we sort integers based on: 1️⃣ Number of set bits in binary representation 2️⃣ If equal, sort by numerical value 💡 Learned: How comparator chaining works Importance of object boxing in Java sorting Clean way to handle multi-level sorting #Java #DSA #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 5 – LeetCode Practice Today, I solved the Reverse Nodes in k-Group problem on LeetCode: 🎯 Difficulty: Hard 💻 Language Used: Java 💡 Approach: • Given a linked list and an integer k, the task was to reverse every group of k nodes. • I used pointer manipulation and a dummy node to handle group reversals cleanly. • Moved through the list in blocks of k, reversing each sub-group by re-wiring next pointers. • Ensured that if the final group had fewer than k nodes, it was kept as-is. • This approach ensured in-place reversal without extra space. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 📚 Key Takeaway: This problem deepened my understanding of in-place linked list manipulation, group operations, and edge-case handling when list length isn’t a multiple of k. Solving pattern-rich, hard problems like this consistently improves my algorithmic thinking and implementation precision. 💪 #LeetCode #Java #DSA #LinkedList #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 8 Today I solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode. At first glance, the problem looks simple: Given a binary string, check whether it contains only one continuous segment of '1's. Example: "110" → Valid (one segment of 1s) "1001" → Invalid (two separate segments of 1s) While solving it, I realized an interesting observation: 👉 If a binary string has more than one segment of 1s, the pattern "01" must appear before another "1". So instead of counting segments explicitly, we can simply check whether '01' appears and is followed by another '1'. This turns the problem into a very efficient linear scan with O(n) time complexity. 💡 Key takeaway: Sometimes the simplest solution comes from recognizing patterns in the string rather than simulating the whole process. Also happy to see my solution running at 0 ms runtime (100% faster) 🚀 #LeetCode #DSA #ProblemSolving #Java #CodingJourney #BinaryStrings
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
Nice 👍