👇 📅 Day 80 of #100DaysOfLeetCode Problem: Max Area of Island (LeetCode #695) Approach: Used Depth-First Search (DFS) to explore each connected component (island) in the grid. Iterated through every cell in the grid. When a land cell (1) was found, initiated a DFS to count all connected land cells. Marked visited cells by changing their value (to avoid recounting). Tracked the maximum island area found during the traversal. Returned the largest area after exploring the entire grid. Complexity: ⏱️ Time: O(m × n) — every cell visited once 💾 Space: O(m × n) — recursion stack in the worst case 🔗 Problem Link: https://lnkd.in/dvUNduuZ 🔗 Solution Link: https://lnkd.in/djiVYpfe #LeetCode #100DaysOfCode #DFS #Graph #GridTraversal #MaxAreaOfIsland #FloodFill #CodingChallenge #ProblemSolving #Java #Algorithms #DataStructures #ProgrammingJourney #DailyCoding #BuildInPublic #TechCommunity #CodeEveryday
"Max Area of Island solved with DFS in Java"
More Relevant Posts
-
🚀 Day 406 of #500DaysOfCode 🎯 Problem: 3318. Find X-Sum of All K-Long Subarrays I 🧩 Difficulty: Easy Today’s challenge focused on computing the X-Sum for every subarray of length k. The X-Sum involves identifying the top X most frequent elements in each subarray — and if frequencies tie, we prioritize larger values. Then, we sum up the occurrences of only those selected elements 💡 💻 Approach: For each subarray of length k, count the frequency of elements. Sort elements by frequency (descending) and value (descending). Pick the top x elements and sum their occurrences in the subarray. Store this result for each subarray. 🧠 Key Concepts Used: Frequency counting using HashMap Custom sorting with comparator logic Sliding subarray analysis 📊 Complexity: O(n × k × log k) 🔍 Topics: Arrays | HashMap | Sorting Every problem solved adds a new pattern to how we think about optimization and logical structuring in code 💪 #Java #LeetCode #ProblemSolving #CodingChallenge #DataStructures #Algorithms #100DaysOfCode #500DaysOfCode
To view or add a comment, sign in
-
-
Day 55 of My DSA Challenge Problem: Count the number of triplets in an array that can form a valid triangle. Concept Recap: For any three sides to form a triangle, the sum of any two sides must be greater than the third side. Optimized Approach: Instead of checking every triplet (which takes O(N³)), I sorted the array and used a two-pointer technique to bring it down to O(N²): Sort the array. Fix the largest side (arr[k]) and use two pointers (i, j) to find pairs where arr[i] + arr[j] > arr[k]. If the condition holds, all elements between i and j can form valid triangles. Count and move pointers accordingly. Time Complexity: O(N²) Space Complexity: O(1) Takeaway: Sorting combined with the two-pointer approach often transforms brute-force solutions into elegant and efficient ones. #Day55 #DSAChallenge #TwoPointerTechnique #Sorting #Optimization #Java #ProblemSolving #DataStructures #Algorithms #CodingChallenge #GeeksforGeeks #LeetCode #100DaysOfCode #ProgrammersJourney #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 145 of #150DaysOfCode on LeetCode 🔹 Problem: 3318. Find X-Sum of All K-Long Subarrays I 🔹 Topic: Sliding Window | HashMap | Sorting Today’s challenge was about computing the X-Sum for every subarray of length k in an array — where the X-Sum is defined as the sum of the top x most frequent elements (considering frequency first and then value). To solve this: I used a sliding window to iterate over all subarrays of size k. For each window, I maintained a frequency map of elements. Then sorted them by frequency (descending) and by value to select the top x contributing elements. Finally, calculated the cumulative X-Sum for each subarray. It was a great exercise in combining maps, sorting logic, and windowing concepts efficiently! 🧩 Key Learnings: How to balance frequency counting with sorting priorities. Importance of optimizing nested loops for small vs. large constraints. Clear understanding of how sorting custom objects impacts runtime. #LeetCode #CodingChallenge #Java #DSA #SlidingWindow #HashMap #ProblemSolving #CodingJourney #100DaysOfCode #WomenInTech #LearnByDoing
To view or add a comment, sign in
-
-
✅Day 46 : Leetcode 69 - Sqrt(x) #60DayOfLeetcodeChallenge 🧩 Problem Statement Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer y should satisfy the condition: y * y <= x < (y + 1) * (y + 1) You must not use any built-in exponent functions such as pow(x, 0.5) or Math.sqrt(x). 💡 My Approach I used a binary search approach to efficiently find the integer square root. The search space is between 1 and x. At each step, I calculate mid and compute val = (long) mid * mid to avoid overflow. If val <= x, I move to the right half (low = mid + 1) and update the answer as mid. If val > x, I move to the left half (high = mid - 1). When the loop ends, ans contains the largest integer whose square is less than or equal to x. ⏱ Time Complexity O(log x) — Binary Search reduces the range by half each time. 💾 Space Complexity O(1) — Constant extra space. #LeetCode69 #BinarySearch #Math #SquareRoot #IntegerSquareRoot #Java #DataStructures #Algorithms #DSA #LeetCodeEasy #ProblemSolving #EfficientCode #OverflowHandling
To view or add a comment, sign in
-
-
#Day-62 ) Solved LeetCode #2528 – Maximize the Minimum Powered City 🔍 Tackled this optimization challenge using binary search + difference array for efficient power distribution across cities. 💡 Key insight: simulate power coverage with a sliding window and greedily allocate extra stations to maintain minimum power. 📈 Time complexity: O(n log(maxPower)), space: O(n) 🧠 Languages used: Java ✅ Problem solved as part of my daily grind to sharpen algorithmic thinking! 📌 Let me know if you'd approach it differently or spot any optimization! #LeetCode #Java #DailyCoding #BinarySearch #Optimization #TechPrep #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 109 of My DSA Challenge – Intersection of Two Arrays 🔷 Problem : 349. Intersection of Two Arrays 🔷 Goal : Return the unique intersection of two integer arrays. Order doesn’t matter, but duplicates should not appear in the result. 🔷 Key Insight : This is a set / hashmap based lookup problem. We store elements from the first array, then check if elements from the second array exist in it. To ensure uniqueness, we remove the element once counted, so duplicates don't appear. 🔷 Approach : 1️⃣ Add all elements of nums1 to a HashMap 2️⃣ Traverse nums2 3️⃣ If the element exists in the map → add to result & remove from map 4️⃣ Convert list to array and return Time Complexity: O(n + m) Space Complexity: O(n) Sometimes the simplest tools — like HashMaps/Sets — give the cleanest solutions. Learning to choose the right data structure = faster logic + cleaner code 💪 #Day109 #100DaysOfCode #LeetCode #DSA #Java #HashMap #DataStructures #CodingChallenge #Algorithm #ProblemSolving #Programming #SoftwareEngineering #TechJourney #DeveloperJourney #CodeEveryday #LearnDSA #LogicBuilding #GrowthMindset #EngineerMindset
To view or add a comment, sign in
-
📅 Day 90 of #100DaysOfLeetCode Problem: Smallest String Starting From Leaf (LeetCode #988) Approach: We are given a binary tree where each node stores a value from 0 to 25, representing letters 'a' to 'z'. We must form strings from leaf → root and return the lexicographically smallest one. To solve this: ✅ Use DFS to explore all paths ✅ Convert node values to characters ✅ Build strings from bottom to top ✅ Track the minimum lexicographical string Key Idea: Perform a DFS traversal and store the path characters. Whenever we reach a leaf, reverse the current path (leaf → root order), form a string, and compare it with the current smallest string. Steps: DFS from root to all leaves Maintain list of path characters When at leaf → form & compare the string Return the smallest lexicographical string found Complexity: ⏱️ Time: O(n × h) — exploring all paths & string creation 💾 Space: O(h) — recursion stack & path storage where h = height of tree 🔗 Problem Link: https://lnkd.in/dyuMJ8QK 🔗 Solution Link: https://lnkd.in/d8hgy4N8 #LeetCode #100DaysOfCode #BinaryTree #DFS #TreeTraversal #StringProblems #LexicographicalOrder #DataStructures #Java #Algorithms #ProblemSolving #DailyCoding #CodingChallenge #BuildInPublic #SoftwareEngineering #LearnToCode
To view or add a comment, sign in
-
-
#Day_23 💡 Problem Solved: Intersection of Two Arrays Today’s challenge tested my ability to handle array manipulation and two-pointer logic efficiently. 🧩 Problem Overview: Given two integer arrays, the task is to find their intersection — meaning the common elements between both arrays, including duplicates. For example: nums1 = [4,9,5] and nums2 = [9,4,9,8,4] 👉 Output should be [4,9] (since both 4 and 9 appear in both arrays). ⚙️ My Approach: Sorting both arrays: By sorting nums1 and nums2, I was able to efficiently compare elements in a linear scan. Two-pointer technique: I used two indices i and j, starting from 0 in each array. If both elements matched → it’s part of the intersection. If one was smaller → move that pointer ahead to catch up. Storing results dynamically: Added all matching elements into an ArrayList. Finally converted it into an integer array for the result. This approach ensures O(n log n) time complexity due to sorting, but O(n) in space — a solid balance between clarity and performance. 🧠 Key Takeaways: Sorting simplifies complex comparison problems. The two-pointer pattern is extremely useful for dealing with sorted arrays. Always remember: clean logic > brute force. 🔥 Every new problem brings a fresh perspective on optimizing logic and learning better ways to handle data structures. #Java #CodingChallenge #LeetCode #100DaysOfCode #ProblemSolving #DSA #ProgrammingJourney #TechWithMudassir
To view or add a comment, sign in
-
-
🚀 Day 22 of #Blind75 Challenge 🎯 Problem: Invert Binary Tree 🧩 Platform: LeetCode (#226) 💡 Category: Binary Tree / DFS 🧠 Problem Statement Given the root of a binary tree, invert it so that every left child becomes the right child and vice-versa. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 💡 Intuition This is one of the cleanest examples of how powerful recursive DFS can be. At each node: Swap its left and right child Recursively invert the left subtree Recursively invert the right subtree The structure updates itself naturally using recursion — no additional data structure required. ⚙️ Complexity ⏱ Time: O(n) — visiting each node once 💾 Space: O(h) — recursion stack (h = tree height) ✨ Key Takeaway Binary tree problems become drastically simpler once you recognize how recursion naturally matches the tree’s structure. “Invert Binary Tree” is the perfect warm-up to mastering tree traversals, DFS, and recursion patterns. 📚 Full solutions at my LeetCode profile: 👉 https://lnkd.in/gGEwKNFV #Blind75 #LeetCode #Java #BinaryTrees #DFS #DSA #CodingChallenge #SoftwareEngineering #ProblemSolving #CareerGrowth #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