📅 Day 43 of #100DaysOfLeetCode 🧩 Problem: 944. Delete Columns to Make Sorted ⚡ Difficulty: Easy 🚀 What I learned today: Visualized the input as a grid of characters (row-wise strings, column-wise comparison) Iterated column by column and checked if characters are lexicographically sorted top to bottom As soon as a column violates sorting (strs[i][j] < strs[i-1][j]), it must be deleted Early break optimization avoids unnecessary comparisons 🧠 Approach: Loop through each column Compare adjacent rows in that column Count columns where the order is not non-decreasing ⏱️ Complexity: Time: O(n × m) Space: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Delete Columns to Make Sorted LeetCode Challenge
More Relevant Posts
-
🚀 Day 76/100 - Problem of the day :- Delete Columns to Make Sorted 🎯 Goal Identify the minimum number of columns to delete so that each remaining column is sorted lexicographically from top to bottom. 🧠 Core Idea Traverse column by column. For each column, check whether characters are in non-decreasing order across all strings. If a column breaks the order, it must be deleted. ✨ Key Takeaway Sometimes the simplest column-wise comparison approach gives the most optimal and readable solution. Always think about breaking the problem into reusable checks. 📦 Space Complexity O(1) — No extra space used apart from variables. ⏱ Time Complexity O(n × m) n = number of strings m = length of each string #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Algorithms #TechSkills #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
-
Day 16 of my LeetCode Journey Problem: Group Anagrams Approach 1 (Primary): Used a HashMap where the key is the word’s sorted characters. All anagrams produce the same sorted string, so they naturally group together. Convert word → char array Sort lexicographically Use sorted string as key Store original words as values Why it works? Anagrams share identical sorted forms. Time Complexity: O(n * k log k) Alternative Optimization: Instead of sorting, use a character frequency array (26 letters) as the key. This avoids sorting and improves time complexity. Time Complexity: O(n * k) Key insight: Choosing the right hash key representation can significantly impact performance. On to Day 17 💪 #LeetCode #DSA #Java #ProblemSolving #Consistency #CodingJourney #1001DaysOfCode Space Complexity: O(n * k)
To view or add a comment, sign in
-
-
🚀 DSA Series – Day 29 📌 Problem: Find the Duplicate Number (LeetCode) Today I worked on a classic array problem where the goal is to find the single duplicate number in an array containing n+1 integers from 1 to n. 🧠 What I learned Instead of sorting or nested loops, we can use a frequency array to track how many times each number appears. If a number appears more than once, that is our duplicate. 💡 My Approach -Create an extra array to store counts -Traverse the input array and increase the count -Scan the count array to find the value with frequency > 1 ⏱ Complexity Time: O(n) Space: O(n) #DSA #LeetCode #Java #ProblemSolving
To view or add a comment, sign in
-
-
📅 Day 46 of #100DaysOfLeetCode 🧩 Problem: 2054. Two Best Non-Overlapping Events ⚙️ Difficulty: Medium 🚀 What I learned today: How to maximize value by selecting at most two non-overlapping intervals Importance of sorting events by end time to enable efficient lookups Used prefix maximum array to store the best value so far Applied binary search to find the last event that ends before the current one starts Achieved an optimal O(n log n) solution for large constraints 🧠 Key Insight: Instead of checking all pairs, precompute the best past event and combine it smartly using binary search. 💡 Techniques Used: Sorting • Binary Search • Prefix Max • Greedy ⏱ Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 31 of #100DaysOfCode Solved LeetCode Problem #944 – Delete Columns to Make Sorted. A clean and straightforward problem focused on checking column-wise ordering across multiple strings. The goal was to identify and remove columns that break lexicographical order. Key Learnings: -> Iterated column by column instead of row-wise -> Detected early breaks to optimize checks -> Reinforced understanding of string indexing and comparisons -> Simple logic, but careful traversal mattered Language Used: Java -> Runtime: 7 ms (Beats 92.96%) -> Memory: 47.16 MB Consistency beats intensity. On to the next problem 💪 #LeetCode #Java #Strings #ProblemSolving #100DaysOfCode #Algorithms
To view or add a comment, sign in
-
-
#200DaysOfCode – Day 105 Backtracking & Recursion 🔹 Problem:- Combination Sum (LeetCode 39) Task: Given an array of distinct integers and a target value, find all unique combinations where the chosen numbers sum to the target. Each number can be used multiple times. Example: Input: candidates = [2,3,6,7], target = 7 Output: [[2,2,3], [7]] My Approach: Used Backtracking to explore all possible combinations. At each step, decided to pick or skip the current element. Allowed reuse of elements by staying on the same index. Backtracked once the target became negative or a valid combination was found. Time Complexity: Exponential (based on number of combinations) Space Complexity: O(Target) (recursion stack + current path) Key Takeaway: Backtracking is all about choices and reversals. Once the pick / not-pick pattern becomes clear, complex problems start feeling much simpler. #takeUforward #200DaysOfCode #Java #Backtracking #Recursion #ProblemSolving #LeetCode #DSA #CodeNewbie #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🔹 Day 97 – LeetCode Practice 📌 Problem: Divide Array Into Equal Pairs (LeetCode #2206) 📊 Difficulty: Easy 🧠 Problem Overview: You’re given an integer array containing 2n elements. The goal is to check whether the array can be divided into n pairs such that: Every element is used exactly once Both elements in each pair are equal ✅ Approach Used: Sorted the array to bring identical elements together. Traversed the array while counting occurrences of each number. Verified that every number appears an even number of times, ensuring valid pairs. 📈 Submission Results: Status: Accepted ✅ Runtime: 8 ms Memory Usage: 46.94 MB 💡 Reflection: This problem is a great reminder that sorting can simplify pairing logic significantly. Once the array is ordered, validating pairs becomes straightforward and efficient. #LeetCode #ProblemSolving #Arrays #Java #DSA #CodingPractice #Consistency
To view or add a comment, sign in
-
-
#200DaysOfCode – Day 109 Problem: LeetCode 17 – Letter Combinations of a Phone Number Task:- Given a string of digits (2–9), return all possible letter combinations based on the phone keypad mapping. Example: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] My Approach: Used a mapping array to store digit-to-letter relationships. Applied backtracking to build combinations character by character. Once the current combination length matched the input length, added it to the result list. Used StringBuilder for efficient string manipulation. Time Complexity: O(4ⁿ) Space Complexity: O(n) (recursive stack) Backtracking is a powerful technique when dealing with combinations and permutations. Breaking the problem into smaller recursive steps makes complex logic much easier to handle. #takeUforward #200DaysOfCode #LeetCode #Java #Backtracking #Recursion #ProblemSolving #DSA #CodeNewbie #Consistency #LearnEveryDay
To view or add a comment, sign in
-
-
🚀 Day 147 | Frequency Counting Across Multiple Strings Today’s problem was a clean exercise in comparing character frequencies across multiple inputs. 🧩 Problem Solved: 1002. Find Common Characters 🔍 Approach: • Initialized a frequency array using the first word. • For each subsequent word, counted character frequencies and kept the minimum count for each character. • Constructed the result by adding each character as many times as its final minimum frequency. ✨ Key Insight: Using minimum frequency across all strings ensures only truly common characters are included. 📚 Topics: Hashing · Strings · Frequency Counting 💻 Platform: LeetCode #LeetCode #DSA #ProblemSolving #DailyCoding #Strings #Hashing #Java #Consistency
To view or add a comment, sign in
-
-
Day 45/100 – #100DaysOfCode 🚀 Solved Remove All Adjacent Duplicates in String (LeetCode) using a Stack. Approach : -> Traverse the string character by character. -> If the stack is not empty and the top character is the same as the current one → pop it (remove the duplicate). -> Otherwise, push the current character onto the stack. -> After processing the full string, the stack contains the final characters (in reverse order). -> Build the result by popping from the stack and reversing it. This approach works in O(n) time and avoids unnecessary comparisons. #DSA #Stacks #LeetCode #ProblemSolving #Java #LearningEveryday #100DaysOfCode
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 approach.