🚀 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
Delete Columns for Lexicographic Order
More Relevant Posts
-
🚀 Day 128 | Two Pointers & In-Place String Processing Today’s problem focused on compressing a character array in-place, reinforcing careful pointer movement and efficient string handling. 🧩 Problem Solved: 443. String Compression 🔍 Approach: • Used two pointers — one to read characters and one to write the compressed output. • Counted consecutive repeating characters. • Wrote the character followed by its count (if greater than 1). • Ensured all modifications were done without extra space. ✨ Key Insight: In-place problems demand precise pointer control. A clean read/write separation keeps the logic simple and avoids overwriting data. 📚 Topics: Two Pointers · Strings · In-Place Algorithms 💻 Platform: LeetCode #LeetCode #DSA #ProblemSolving #DailyCoding #TwoPointers #Strings #Java #Consistency
To view or add a comment, sign in
-
-
🚀 Day 41 of #100DaysOfCode Solved LeetCode Problem #840 – Magic Squares in Grid ✨🔢 This problem focused on identifying all 3×3 subgrids that form a valid magic square, where every row, column, and diagonal sums to the same value and all numbers from 1 to 9 appear exactly once. Key Learnings: -> Iterated through all possible 3×3 subgrids efficiently -> Validated uniqueness of numbers using a boolean check array -> Verified row, column, and diagonal sums against a target sum -> Reinforced careful condition checking to avoid false positives Language Used: Java -> Runtime: 0 ms (Beats 100.00%) -> Memory: 43.22 MB Precision and validation go hand in hand—small grids, strict rules, clean logic 🚀 #LeetCode #Java #BruteForce #Matrix #ProblemSolving #Algorithms #100DaysOfCode
To view or add a comment, sign in
-
-
Day - 34 Longest Common Prefix The problem - Write a function to find the longest common prefix string amongst an array of strings. Example : strs = [“flower”,”flow”,”flight”] -> “fl” strs=[“dog”,”racecar”,”car”] -> “” Brute force - Compare all the characters at each position across the strings, but the time complexity will be O(S), S is sum of all characters and require multiple traversals. Approach Used - Horizontal Scanning •) Handle edge case: if array is null or empty, return "". •) Initialise pref = strs[0], prefLen = prefix.length(). •) while(prefLen > s.length()) or pref doesn't match the beginning of s (or prefix is longer than s) 1 - Reduce prefix length by 1 (prefLen--). 2 - If prefLen becomes 0, no common prefix exists - return "". 3 - Update prefix to pref.substring(0, prefLen). 4 - Continue to next string. •) Return the final pref. Complexity - Time - O(S), total number of characters in all strings. Space - O(1), only used variables. #DSA #Java #SoftwareEngineering #InterviewPrep #LearnToCode #CodeDaily #ProblemSolving
To view or add a comment, sign in
-
-
📅 Day 62 of #100DaysOfLeetCode 🔢 Problem: 1458. Max Dot Product of Two Subsequences 🟥 Difficulty: Hard 🧠 Problem Summary Given two integer arrays, find the maximum dot product between non-empty subsequences of equal length while preserving order. 💡 Key Insight This problem is a DP + subsequence variant similar to LCS, but with an important twist: 👉 The answer can be negative, so initializing DP with 0 will fail. 👉 We must ensure at least one pair is chosen. 🚀 Approach (Memoization / Top-Down DP) Use recursion with indices (i, j) At each step, consider: Pairing nums1[i] with nums2[j] Skipping an element from either array Use Math.max(0, previous) to avoid extending negative subsequences Memoize results to achieve O(n × m) complexity ⏱ Complexity Time: O(n × m) Space: O(n × m) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
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 - 28 Median of Two Sorted Arrays The problem - Find the Median of two sorted arrays. Example : nums1 = [1,3], nums2 = [2] -> 2.0 nums = [1,2], nums2 = [3,4] -> 2.5 Brute force - Merge both arrays and find the Median. Approach Used - Two Pointers •) Initialize n=nums1.length, m=nums2.length, i=0,j=0. •) Track two variables, m1(current middle element), m2(previous middle element). •) Loop until we reach the median position, count from 0 to (n+m)/2. •) In each iteration, save current m1 as m2.Compare elements at i and j. 1 - If both arrays have elements remaining, pick smaller one and move that pointer. 2 - If only nums1 has elements, take from nums1(i++). 3 - If only nums2 has elements, take from nums2(j++). •) After loop ends, if total length is odd, median = m1, if total length is even, median = (m1+m2)/2. •) Return the median. Complexity - Time - O(m+n), we iterate until median position. Space - O(1), we use pointers. #DSA #Java #SoftwareEngineering #InterviewPrep #LearnToCode #CodeDaily #ProblemSolving
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
-
-
🚀 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 13/100 – LeetCode Challenge ✅ Problem: #368 Largest Divisible Subset Difficulty: Medium Language: Java Approach: Dynamic Programming with Path Reconstruction Time Complexity: O(n²) Space Complexity: O(n) Key Insight: After sorting, a divisible subset maintains divisibility chain: If nums[i] % nums[j] == 0, extend subset from j to i. Track both DP count and previous index for reconstruction. Solution Brief: Sorted array and initialized dp[i]=1, prev[i]=-1. Nested loops to build longest divisible chain, storing parent indices. Reconstructed subset by backtracking from maxi using prev array. Finding structured subsets with divisibility chains #LeetCode #Day13 #100DaysOfCode #DynamicProgramming #Java #Algorithm #CodingChallenge #ProblemSolving #LargestDivisibleSubset #MediumProblem #PathReconstruction #Subset #DSA #Array
To view or add a comment, sign in
-
-
#Day_59 Problem: 4Sum (LeetCode 18) Day 57 pushed the limits with 4Sum — finding all unique quadruplets equal to a target! 💥 🧠 Key Takeaways: This is an extension of 3Sum → fix two elements + two pointers. Sorting is the backbone. Duplicate skipping at both outer and inner levels is critical. Use long for sum to avoid overflow. ⚙️ Optimized Approach: Sort the array. Fix i and j. Apply two pointers for remaining part. Carefully skip duplicates. ⏱️ Complexity: O(n³), but still efficient compared to brute force. 📌 This problem taught me: How patterns scale from 2Sum → 3Sum → 4Sum. Writing clean, duplicate-free logic. Consistency + patterns = confidence! 💪 #Day57 #4Sum #LeetCode #Java #DSA #CodingPractice #LearnByDoing
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