🚀 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
LeetCode 840: Magic Squares in Grid Java Solution
More Relevant Posts
-
🚀 Day 67 of #100DaysOfCode Solved LeetCode Problem #1984 – Minimum Difference Between Highest and Lowest of K Scores ✅ This problem focused on minimizing the score gap by smartly selecting k elements after sorting the array. A perfect example of how sorting + sliding window logic can turn a problem simple and efficient. Key Learnings: -> Sorting simplifies comparisons -> Sliding window to evaluate consecutive groups of size k -> Avoid brute force by leveraging order -> Small observations lead to clean solutions Language Used: Java -> Runtime: 8 ms (Beats 89.22%) -> Memory: 47.09 MB (Beats 25.34%) Consistency > Intensity 💪 On to the next challenge 🚀 #LeetCode #Java #ProblemSolving #Algorithms #Sorting #SlidingWindow #100DaysOfCode
To view or add a comment, sign in
-
-
Day 39/100 – LeetCode Challenge ✅ Problem: #1984 Minimum Difference Between Highest and Lowest of K Scores Difficulty: Easy Language: Java Approach: Sorting + Sliding Window Time Complexity: O(n log n) Space Complexity: O(1) Key Insight: After sorting, the minimum range in k elements must come from consecutive elements in sorted order. Sliding window of size k finds the minimum difference between first and last element in window. Solution Brief: Sorted the array to bring close values together. Initialized answer with first k elements. Slided window across array, updating minimum difference. Finding minimal range in sorted array with sliding window #LeetCode #Day39 #100DaysOfCode #Sorting #SlidingWindow #Java #Algorithm #CodingChallenge #ProblemSolving #MinimumDifference #EasyProblem #Array #Optimization #DSA
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfCode Solved LeetCode Problem #1200 – Minimum Absolute Difference ✅ A clean and elegant problem where sorting does most of the heavy lifting. By comparing adjacent elements after sorting, we can efficiently find all pairs with the minimum absolute difference. Key Learnings: -> Sorting simplifies difference-based problems -> Adjacent comparison is enough after sorting -> Clear logic beats complex data structures -> Collecting results while tracking the minimum difference Language Used: Java -> Runtime: 20 ms (Beats 97.70%) -> Memory: 64.05 MB (Beats 32.62%) Step by step, day by day 🚀 On to the next problem 💪 #LeetCode #Java #ProblemSolving #Algorithms #Sorting #Arrays #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 69 of #100DaysOfCode Solved LeetCode Problem #3650 – Minimum Cost Path with Edge Reversals ✅ This problem was a great application of graph algorithms, where the goal was to minimize cost by smartly handling edge directions and reversals. Modeling the problem correctly made all the difference. Key Learnings: -> Converting edge reversals into weighted edges -> Using graph representation effectively -> Applying Dijkstra’s algorithm for shortest path -> Thinking beyond direct edges to optimize cost Language Used: Java -> Runtime: 75 ms (Beats 85.02%) -> Memory: 275.60 MB (Beats 39.27%) Consistency > Motivation 🚀 Onwards to Day 68 💪 #LeetCode #GraphAlgorithms #Dijkstra #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Solved LeetCode 4 – Median of Two Sorted Arrays ✅ Yeah, I know. This is a Hard problem and the expected solution is O(log(min(n, m))) using binary search and partitioning. But today, I went with clarity first. I combined both arrays, sorted them, and directly computed the median. 📌 Result? ✔️ All test cases passed ✔️ Correct output ✔️ Clear logic Is it the optimal solution? ❌ Is it a valid one? ✅ And that’s the point. Sometimes the real learning is: Understanding why a brute-force solution works Then understanding why it’s not optimal And only then moving to the complex solution Hard problems aren’t solved in one jump. They’re solved in iterations. Binary search partitioning is next. But today, correctness comes first. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 44 of #100DaysOfCode Solved LeetCode Problem #961 – N-Repeated Element in Size 2N Array This problem was about identifying the element that repeats N times in an array of size 2N. The key insight is that the repeated element must appear very close to itself, allowing an efficient linear scan without extra space. Key Learnings: -> Used observation-based logic instead of extra data structures -> Checked only nearby indices to detect repetition early -> Achieved optimal O(n) time and O(1) space -> Reinforced pattern recognition in array problems Language Used: Java -> Runtime: 0 ms (Beats 100.00%) -> Memory: 47.85 MB Small observations can lead to optimal solutions 🚀 #LeetCode #Java #Arrays #ProblemSolving #100DaysOfCode #DSA
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
-
-
LeetCode Practice - 944. Delete Columns to Make Sorted 🧠 Problem Idea ✅ You are given n strings, all of the same length. ✅ Imagine them written one below another like a grid. Example: cba daf ghi We check column by column. Column 0 → c d g → sorted ✅ Column 1 → b a h → NOT sorted ❌ Column 2 → a f i → sorted ✅ So we delete column 1 → answer = 1 🛠️ Key Observation ✅ A column is sorted if characters do not decrease from top to bottom. That means: 📌 strs[0][col] <= strs[1][col] <= strs[2][col] <= ... ✅ If any pair breaks this rule, that column must be deleted. 🚀 Algorithm 🔷 Take number of rows n 🔷 Take the n strings 🔷 For each column 🔷 Compare every row with the next row 🔷 If upperRowChar > lowerRowChar, mark it as invalid 🔷 Count how many columns are invalid #LeetCode #Java #StringHandling #CodingPractice #ProblemSolving #DSA #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 50 of #100DaysOfCode Solved LeetCode Problem #1458 – Max Dot Product of Two Subsequences ✅ This problem focused on finding the maximum dot product between non-empty subsequences of two arrays. The tricky part was handling negative values and ensuring at least one pair is always chosen. Key Learnings: -> Used Dynamic Programming with memoization to avoid recomputation -> Carefully handled the base case using Integer.MIN_VALUE to enforce non-empty subsequences -> Explored the classic include vs exclude decision at each index -> Strengthened understanding of DP on two sequences Language Used: Java -> Runtime: 11 ms (Beats 59.26%) -> Memory: 48.77 MB Step by step, sharpening DP intuition and edge-case handling 🚀 #LeetCode #DynamicProgramming #Java #ProblemSolving #100DaysOfCode
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
-
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