💻 Day 59 of #100DaysOfCode Challenge 🚀 Today's problem: Leetcode 240 – Search a 2D Matrix II 🔍 This problem was about efficiently searching for a target value in a 2D matrix where each row and each column is sorted in ascending order. 💡 Key Insight: Instead of searching the entire matrix, start from the top-right corner: If the current element is greater than the target → move left. If it’s smaller → move down. This approach ensures that we eliminate one row or one column in every step — achieving O(m + n) time complexity. 📊 Result: ✅ Accepted – All test cases passed successfully! ⚡ Time Complexity: O(m + n) 💾 Space Complexity: O(1) 🧠 Takeaway: This problem was a great reminder that understanding data structure properties can help you find smarter solutions rather than brute-forcing through the problem. Every problem adds another brick to the foundation of logical thinking and algorithmic mastery. 💪 #Day59 #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #TechLearning #DSA
"Day 59 of #100DaysOfCode: Solving Leetcode 240 with O(m + n) complexity"
More Relevant Posts
-
🚀 Day 391 of #500DaysOfCode Today, I solved LeetCode Problem 2011: Final Value of Variable After Performing Operations 🧮 📝 Problem Summary: You start with a variable X = 0 and a list of operations such as "++X", "X++", "--X", or "X--". Each "++" increases the value by 1, and each "--" decreases it by 1. The goal is to return the final value of X after performing all operations. 💡 Approach: Initialize X = 0. Loop through the list of operations. If the operation contains "++", increment X. Otherwise, decrement X. Return the final result. ✅ Example: Input: ["--X","X++","X++"] Output: 1 A simple yet elegant problem that helps sharpen conditional logic and string manipulation fundamentals. ⚡ #LeetCode #CodingChallenge #Java #100DaysOfCode #500DaysOfCode #ProblemSolving #LearnEveryday
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 3: Remove Duplicates from Sorted Array Day 3 of my #LeetCode50DaysChallenge ✅ Today’s problem was about array manipulation — Remove Duplicates from Sorted Array ✨ 🧩 Problem: Given an integer array nums sorted in non-decreasing order, remove duplicates in-place such that each unique element appears only once. The relative order of the elements should remain the same. 💡 Approach: This problem is a classic two-pointer approach! One pointer i keeps track of the last unique element’s position. The other pointer j iterates through the array. Whenever a new element is found (nums[i] != nums[j]), we move it forward by incrementing i and assigning nums[i] = nums[j]. In the end, i + 1 gives the count of unique elements. A simple yet elegant technique to modify arrays in-place! ⏱️ Time Complexity: O(n) 📊 Example: Input: [0,0,1,1,1,2,2,3,3,4] Output: [0,1,2,3,4] Consistency is the secret ingredient to progress! 🌱 Each problem solved adds another brick to the wall of mastery 💪 #LeetCode #CodingChallenge #Day3 #ProblemSolving #Java #SoftwareDevelopment #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
#Day-44) of Problem Solving | LeetCode 2011 – Final Value of Variable After Performing Operations Just solved a fun one! 🚀 This problem tests how well you can interpret simple string-based operations and apply them efficiently. Given a list of operations like "++x", "x--", etc., the goal is to compute the final value of a variable starting from zero. 🔍 My approach (Java): Used String.indexOf("+") to detect increment operations and updated the counter accordingly. Clean, readable, and runs in linear time. #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #PranshuCodes #LinkedInCoding #TechJourney
To view or add a comment, sign in
-
-
🌟 Day 84 of My #100DaysOfCode Challenge 🧩 Problem: LeetCode 108 – Convert Sorted Array to Binary Search Tree 💭 Understanding the Problem Given a sorted array, we need to convert it into a height-balanced Binary Search Tree (BST) — meaning the difference in height between the left and right subtrees of every node should not exceed one. 📘 Example: Input: nums = [-10, -3, 0, 5, 9] Output: [0, -3, 9, -10, null, 5] The middle element (0) becomes the root, left half forms the left subtree, and the right half forms the right subtree. 🧠 Key Idea Pick the middle element as the root for balance. Recursively repeat the same for left and right halves. This approach ensures that the BST remains balanced. ⚙️ Complexity Analysis Time Complexity: O(n) — each element is processed once. Space Complexity: O(log n) — recursion stack in a balanced tree. ✨ Takeaway This problem beautifully combines recursion and binary tree logic, showcasing how dividing the array strategically helps maintain balance in a BST. 💬 "Balanced structures are key to efficiency — both in code and in life!" 😄 #Day84 #LeetCode #Java #DSA #BinaryTree #CodingChallenge #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 11 of 100 Days of LeetCode! 💻 Today’s problem: Implement strStr() 🔍 🧩 Problem #28: Find the Index of the First Occurrence in a String This problem is a classic example of string pattern matching, where we need to find the starting index of a substring (needle) in a given string (haystack). ✨ My Approach: Used a simple sliding window technique to check each substring of haystack with length equal to needle. Compared it directly using equals() to find a match. Time complexity: O((n - m + 1) * m), which is acceptable for moderate input sizes. ✅ Result: All test cases passed successfully — and achieved 100% runtime efficiency ⚡ Each day I’m learning to think more efficiently and write cleaner, more optimized code. Consistency really is the key 🔑 #Day11 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #DSA
To view or add a comment, sign in
-
-
🌳 Day 62 of 100 Days of LeetCode 🌳 Today’s challenge: LeetCode 226 – Invert Binary Tree 🔄 🧩 Problem Summary: Given the root of a binary tree, invert it — meaning swap the left and right children of every node. Essentially, you’re mirroring the entire tree! 🌲✨ 💡 Key Takeaways: 🔹 Strengthened understanding of tree traversal using recursion. 🔹 Learned how a simple DFS (Depth-First Search) can elegantly solve structural transformations. 🔹 Practiced reasoning about symmetry and recursion base cases. 🧠 Approach: 1️⃣ If the tree is empty, return null. 2️⃣ Recursively invert the left and right subtrees. 3️⃣ Swap the left and right children of the current node. 4️⃣ Return the root once the tree is fully inverted. 🚀 A great example of how recursion simplifies complex problems into smaller, intuitive steps! #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #CodingJourney #Recursion #ProblemSolving
To view or add a comment, sign in
-
-
⚙️ Day 38 of My LeetCode Journey — Problem #2654 “Minimum Number of Operations to Make All Array Elements Equal to 1” (Java Solution) 💡 Today’s challenge beautifully combined number theory with algorithmic optimization. The goal: turn every element in an array into 1 using the minimum operations — and the key insight was rooted in GCD properties. 🔍 My thought process: If any 1s exist → we just need to handle the rest (n - count(1)). Otherwise → find the shortest subarray with GCD = 1, since it’s the only way to generate a 1. The final answer = minimal window length + (n - 1) operations. It’s fascinating how understanding mathematical relationships can drastically simplify code complexity 🔢 Each problem reminds me — elegant logic is what turns code into art 🧠💻 #Day38 #LeetCode #Java #ProblemSolving #NumberTheory #Algorithms #DSA #CodingJourney #100DaysOfCode #CodeEveryday #SoftwareEngineering #LearningInPublic #TechCommunity
To view or add a comment, sign in
-
-
🧠 LeetCode Day 97 — Path Sum (Problem 112) Today’s challenge was about checking whether a binary tree has a root-to-leaf path such that adding up all the values along the path equals a given sum. 🔍 Problem Description: Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that the sum of the node values equals targetSum. Otherwise, return false. 💡 Approach: Traverse the tree recursively. Subtract the current node’s value from targetSum. When a leaf node is reached, check if the remaining sum equals zero. Use Depth First Search (DFS) to explore all paths. 🚀 Key Learnings: Strengthened understanding of recursive tree traversal. Practiced handling base cases in recursion effectively. Improved clarity on root-to-leaf path logic in binary trees. 🌳 #Day97 of #100DaysOfCode Each challenge adds a new layer to my problem-solving skills. Binary tree problems like this sharpen the recursive mindset — thinking from root to leaf and back up! 💪 #LeetCode #CodingChallenge #Java #100DaysOfCode #BinaryTree #ProblemSolving #Recursion
To view or add a comment, sign in
-
-
🚀 LeetCode 150 – Lowest Common Ancestor of a Binary Tree 🌳 A recursion-based problem from the LeetCode 150 list! The goal: find the lowest common ancestor (LCA) of two given nodes in a binary tree. 🔹 Approach If the current node is null, return null. If the node matches p or q, return it. Recursively check left and right subtrees. If both return non-null → current node is the LCA. Otherwise, propagate the non-null result upward. 💡 Time: O(N) | Space: O(H) #LeetCode150 #DSA #Java #Recursion #BinaryTree #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 8 of #45DaysOfLeetCode Challenge 😎 📌Today's problem: Palindrome Number (LeetCode #9) 💡 🔹 Concept: Check whether a given integer reads the same backward and forward — without converting it to a string! 🔹 Logic Used: Instead of reversing the entire number, I reversed only half of it to improve efficiency. This avoids unnecessary computation and eliminates integer overflow risks. 🔹 Key Learnings: ✅ Optimized logic using mathematical manipulation ✅ Improved understanding of number reversal techniques ✅ Importance of edge case handling (negative numbers, trailing zeros) ⚙️ Result: 💻 Runtime: 4 ms (Beats 100%) 💾 Memory: 44.84 MB 😎Small optimizations make a big difference in performance! 💪 📌Problem: https://lnkd.in/ef6AC2j6 🔥Each day is a step closer to writing cleaner and more optimized code. ✨ Let’s keep pushing forward and refining our problem-solving skills! 💻🔥 #LeetCode #Day8 #100DaysOfCode #ProblemSolving #Java #CodingChallenge #PalindromeNumber #DataStructures #Algorithms #LearningEveryday
To view or add a comment, sign in
-
Explore related topics
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