Day 45 on LeetCode Largest Submatrix With Rearrangements :- This problem clicked once I stopped treating columns as fixed. Rearranging them turns each row into a controllable histogram. Approach: ->Build vertical heights of consecutive 1s ->Sort each row to simulate optimal column order ->Evaluate max area using height × width Time Complexity: O(m × n log n) The editorial on LeetCode made the difference here. It didn’t just give the solution, it clarified the intuition behind sorting heights, which is easy to miss on your own. #DSA #LeetCode #Java
LeetCode Day 45: Largest Submatrix With Rearrangements
More Relevant Posts
-
The Two-Pointer streak continues! Today’s LeetCode Problem: Is Subsequence. After using multiple pointers to sort arrays and move zeroes, I applied the exact same pattern to string manipulation today. The challenge was figuring out if a shorter string (s) is a valid subsequence of a longer string (t) without disturbing the relative order of the characters. Instead of generating all possible subsequences (which would be a massive O(2ⁿ) performance drain), the Two-Pointer approach solves this beautifully in a single pass. Knocking this out in O(n) time and O(1) space is another great reminder of how incredibly versatile this algorithmic pattern is for both arrays and strings. #DSA #Java #LeetCode #IsSebsequenceProblem
To view or add a comment, sign in
-
-
Day 14 of LeetCode — Longest Common Prefix Today I solved the classic problem: finding the longest common prefix among a list of strings. Approach I used: Start with the first string as the prefix Compare it with each string in the array Shrink the prefix until it matches the start of every string If it becomes empty → no common prefix Time Complexity: O(n * m) (n = number of strings, m = length of prefix) This problem reinforced string manipulation and edge case handling (empty arrays, no matches). #Java #DSA #CodingJourney #LeetCode #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
Taking the Two-Pointer technique to LeetCode! Today's challenge: Remove Duplicates from a Sorted Array. After practicing the Two-Pointer pattern for reversing arrays and swapping 0s and 1s, I applied it to a classic LeetCode problem. The challenge? Remove duplicates from an array in-place with O(1) extra memory. Because the array is already sorted, all duplicates are grouped together. • The Slow Pointer (The Writer): Keeps track of where the next unique element should be placed. • The Fast Pointer (The Reader): Scans ahead through the array to find new, unique numbers. • The Logic: If the Reader finds a duplicate, it just skips it. But the moment the Reader finds a new number, the Writer records it at the front of the array and steps forward. #DSA #Java #LeetCode #RemoveDuplicate
To view or add a comment, sign in
-
-
💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
💡 Day 36 of LeetCode Problem Solved! 🔧 🌟11. Container With Most Water🌟 Task : You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Example 1: GInput: height = [1,8,6,2,5,4,8,3,7] Output: 49 Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49. Example 2: Input: height = [1,1] Output: 1 #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
🚀 Day 23 of #128DaysOfCode Today I solved an interesting string problem where one string is shuffled and an extra character is added. 🔍 What I learned: - How to use character ASCII values to simplify problems - Instead of comparing strings directly, we can use sum difference logic - Converting between char and int makes calculations easier and efficient 💡 Key idea: If we add all characters of both strings and subtract, the remaining value gives the extra character. ⚡ This approach is simple, clean, and runs in O(n) time with O(1) space. Consistency is building momentum 🔥 #Java #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 72 of My LeetCode Journey with edSlash Today’s problem: Remove Linked List Elements (LeetCode 203) 🔍 What I learned: How to efficiently remove nodes from a linked list Importance of using a dummy node to handle edge cases (especially when the head needs to be deleted) Cleaner traversal by checking curr.next instead of curr 💡 Key Insight: Using a dummy node simplifies the logic and avoids unnecessary special handling for the head node. ⚡ Approach: Create a dummy node pointing to head Traverse the list Skip nodes where value == target 📈 Complexity: Time: O(n) Space: O(1) Consistency is the real key 🔑 — 72 days and still going strong! #Day72 #LeetCode #DSA #LinkedList #Java #CodingJourney #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
100 Days of Code Day-14 Solved a classic problem: Longest Common Prefix Given an array of strings, the task is to find the longest common prefix shared among them. If no common prefix exists, return an empty string. Approach: Used a simple horizontal scanning method: Start with the first string as the prefix Compare it with each string Gradually reduce the prefix until it matches all strings Example: "flower", "flow", "flight" → "fl" "dog", "racecar", "car" → "" A good exercise to strengthen string handling and logical thinking. #Java #DSA #ProblemSolving
To view or add a comment, sign in
-
-
🚀 100 Days of Code Day -27 LeetCode Problem solved- Divide Two Integers Solved this interesting problem where division is performed without using multiplication, division, or mod operators. 💡 Key Learnings: Used bit manipulation (left shift) to optimize repeated subtraction Handled edge cases like overflow (Integer.MIN_VALUE) Achieved efficient solution with O(log n) complexity 📌 This problem really strengthens understanding of low-level operations and optimization techniques. Always fascinating to see how basic operations can be built from scratch! #LeetCode #Java #DSA #CodingInterview #ProblemSolving
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟔𝟕 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding the smallest subarray with sum ≥ target. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Minimum Size Subarray Sum 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐒𝐥𝐢𝐝𝐢𝐧𝐠 𝐖𝐢𝐧𝐝𝐨𝐰 • Maintained a window using two pointers (left & right) • Expanded the window by moving right pointer • Once sum ≥ target: • Shrunk the window from the left • Updated the minimum length This ensures we always keep the smallest valid window. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Sliding window works well for subarray problems • Expand → to meet condition • Shrink → to optimize result • Two pointers reduce time complexity significantly 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sliding window is about balance — expand when needed, shrink when possible. 67 days consistent 🚀 On to Day 68. #DSA #Arrays #SlidingWindow #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
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
Kitna questions solve kr liye h