🚀 Day 20 of #100DaysOfCode Solved 54. Spiral Matrix on LeetCode 🌀 🧠 Key insight: Spiral traversal is all about maintaining boundaries. By shrinking the top, bottom, left, and right limits after each pass, we can cover every element exactly once. ⚙️ Approach: 🔹Maintain four pointers: top, down, left, right 🔹Traverse: 🔹Left → Right (top row) 🔹Top → Bottom (right column) 🔹Right → Left (bottom row) 🔹Bottom → Top (left column) 🔹Update boundaries after each traversal ⏱️ Time Complexity: O(m × n) 📦 Space Complexity: O(1) (excluding output list) #100DaysOfCode #LeetCode #DSA #Matrix #Java #ProblemSolving #LearningInPublic #CodingJourney
Spiral Matrix LeetCode Solution
More Relevant Posts
-
#Day58 of my second #100DaysOfCode Today’s problem was about carefully handling overlapping intervals. DSA • Solved Merge Intervals (LeetCode 56) • Implemented a brute force approach by checking and merging overlapping intervals → O(2n) + O(n log n) time • Implemented the optimal approach by sorting intervals and merging them in a single traversal → O(n log n) + O(n) time • Key idea: once intervals are sorted by start time, overlapping ranges can be merged efficiently in one pass These interval problems really test attention to detail with edge cases. #DSA #Algorithms #LeetCode #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 31 of #100DaysOfCode Solved 240. Search a 2D Matrix II on LeetCode 🔍📊 🧠 Key insight: In this matrix, each row is sorted left → right and each column is sorted top → bottom. Starting from the top-right corner lets us eliminate an entire row or column at each step. ⚙️ Approach: 🔹Start at top-right element 🔹If value equals target → return true 🔹If value is smaller → move down (increase row) 🔹If value is larger → move left (decrease column) 🔹Continue until the target is found or boundaries are crossed ⏱️ Time Complexity: O(m + n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #Matrix #TwoPointers #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
#Day67 of my second #100DaysOfCode Today’s problem pushed me to think carefully about comparisons and sorting logic. DSA • Solved Reverse Pairs (LeetCode 493) — count pairs (i, j) such that i < j and nums[i] > 2 * nums[j] • Brute force: check every pair using nested loops → O(n²) time • Optimal approach: Modified Merge Sort to count valid pairs during merge → O(2n log n) time, O(n) space • Key insight: count pairs across the left and right halves before merging. Another reminder of how divide-and-conquer + merge sort patterns appear in many hard problems. #DSA #Algorithms #LeetCode #MergeSort #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 41 💻 LeetCode – Add to Array-Form of Integer Today I solved a problem focused on array manipulation and digit-by-digit addition. 🔎 Problem: An integer is given in array form, where each element represents a digit. The task is to return the array representation of num + k. 💡 Approach: Instead of converting the array into a number, I simulated manual addition from the last digit, just like we do on paper. ✔ Traverse the array from right to left ✔ Add digits with k and manage the carry ✔ Store the result digits and reverse at the end This approach efficiently handles large inputs and avoids integer overflow. Small problems like this strengthen logic building and problem-solving skills. #LeetCode #DSA #100DaysOfCode #ProblemSolving #Java #CodingJourney #SoftwareDeveloper #TechGrowth
To view or add a comment, sign in
-
-
Most problems aren’t about brute force. They’re about recognizing patterns. Today’s focus: Day 48/100 – Sliding Window Mastery 🚀(Longest Subarray with At Most 2 Distinct Elements) Instead of checking every possible subarray (O(n²)), I used the Sliding Window + HashMap approach to optimize it to O(n) time complexity. 🔹 Expand the window using r 🔹 Track frequencies using HashMap 🔹 Shrink from l when distinct elements exceed 2 🔹 Update maximum length dynamically Clean. Efficient. Scalable. Consistent practice is making pattern recognition faster and more intuitive every day. #Day48 #100DaysOfCode #DSA #Java #CodingJourney #SlidingWindow #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
Day 16/100 – LeetCode Challenge Problem: Merge Sorted Array Today’s problem involved merging two sorted arrays into one sorted array. Approach: Created a temporary array of size m + n Used two pointers to compare elements from both arrays Inserted the smaller element into the new array Copied remaining elements if any array still had values Finally copied the merged result back into nums1 Complexity: Time: O(m + n) Space: O(m + n) Concepts Practiced: Two-pointer technique Array traversal Merging sorted arrays #100DaysOfCode #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 17/100 – LeetCode Challenge Problem Solved: Spiral Matrix Today’s problem required traversing a matrix in spiral order, starting from the top-left corner and moving right, down, left, and up repeatedly until all elements are visited. The key idea is to maintain four boundaries that represent the current layer of the matrix being processed: top, bottom, left, and right. We move in four directions step by step: ->Traverse from left to right across the top row. ->Traverse from top to bottom along the right column. ->Traverse from right to left across the bottom row. ->Traverse from bottom to top along the left column. After completing each direction, the corresponding boundary is adjusted inward so the traversal continues with the inner layer of the matrix. This process continues until the boundaries cross, ensuring every element is visited exactly once. Time Complexity: O(m × n) Space Complexity: O(1) (excluding the result list) Performance: Runtime 0 ms Key takeaway: Many matrix traversal problems become manageable when you define clear boundaries and shrink them step by step. Day 17 completed. Continuing the journey of strengthening algorithmic thinking through consistent practice. #100DaysOfLeetCode #Java #Algorithms #MatrixTraversal #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟐𝟓 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on sorting an array containing only three distinct values using an efficient counting approach. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Sort Colors 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝟏 – 𝐂𝐨𝐮𝐧𝐭𝐢𝐧𝐠 𝐀𝐫𝐫𝐚𝐲 • Created a count array of size 3 • Counted occurrences of 0, 1, and 2 • Overwrote the original array using the frequency values • Simple and easy to implement 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • When value range is small, counting is powerful • Rewriting the array can be simpler than swapping • Constraints often guide the optimal approach • Clear thinking avoids overcomplication 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) (since count array size is constant) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Not every sorting problem needs full sorting logic — sometimes counting is enough. 25 days consistent. On to Day 26 🚀 #DSA #Arrays #Sorting #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 11 of #60DaysOfCode Solved a challenging tree problem today: 👉 Largest BST in a Binary Tree 🌳 Problem Statement: Given a binary tree, find the size of the largest subtree that satisfies Binary Search Tree (BST) properties. 💡 Approach: Used a postorder traversal (bottom-up approach) to efficiently determine whether each subtree is a BST. For every node, tracked: - Minimum value - Maximum value - Size of subtree - Whether it's a valid BST If a subtree satisfies BST conditions, we compute its size. Otherwise, we carry forward the maximum size found so far. ⚡ Key Insight: Instead of checking each subtree separately (which is inefficient), we combine results during traversal — achieving O(N) time complexity. ✅ Successfully passed all test cases! 🔍 This problem really strengthened my understanding of: - Tree Traversals - Recursion - Optimized problem-solving #DataStructures #Java #CodingJourney #BinaryTree #BST #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Leetcode Problem || Minimum Operations to Equalize Binary String Solved(3666)🚀 Today I worked on an interesting problem involving string transformation operations. Instead of simulating every flip operation directly on the string (which would be expensive), I optimized the approach by: ✔ Converting the problem into tracking only the count of zeros ✔ Modeling the transformation as a graph problem ✔ Using BFS to find minimum operations ✔ Leveraging TreeSet for efficient range pruning ✔ Applying parity-based optimization for faster traversal #Java #DSA #BFS #ProblemSolving #CompetitiveProgramming #CodingJourney
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