Day 5/100 – LeetCode Challenge Problem: Word Search Today’s challenge was a classic 2D Matrix + DFS + Backtracking problem. Problem Summary: Given a 2D board of characters and a word, determine if the word exists in the grid. Rules: Adjacent cells = horizontal or vertical A cell cannot be reused in the same path Approach Used: Traverse every cell as a starting point Apply Depth First Search (DFS) Mark visited cells temporarily Backtrack after exploring all 4 directions Core idea: Base case → If index == word.length() → return true Boundary check + character match validation Mark visited → Explore → Restore (Backtracking) Key Concepts Practiced: Recursion Backtracking 2D matrix traversal State modification & restoration Time Complexity: O(m × n × 4^L) (L = length of word) This problem reinforced an important lesson: Backtracking is about exploring possibilities and undoing choices efficiently. #100DaysOfCode #LeetCode #DSA #Java #Backtracking #SoftwareEngineerJourney #CodingInterview
LeetCode Challenge: Word Search in 2D Matrix with DFS and Backtracking
More Relevant Posts
-
🔥 Day 82 of my LeetCode Journey 🔥 📘 Problem: 110. Balanced Binary Tree 🎯 Difficulty: Easy 🔹 Problem Statement: Given a binary tree, determine if it is height-balanced. A binary tree is balanced if the height difference between the left and right subtree of every node is not more than 1. 🔹 Approach Used: Traverse the tree using Depth First Search (DFS) Calculate the height of left and right subtrees recursively If the height difference exceeds 1, return -1 to indicate the tree is not balanced Otherwise, return the height of the current node Finally, check if the returned value is -1 or not 🔹 Key Concepts: Binary Tree traversal Depth First Search (DFS) Recursion Height calculation of tree 🔹 Learning: Instead of calculating heights separately for every node (which would increase complexity), this approach combines height calculation and balance checking in a single traversal, making the solution more efficient. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) #LeetCode #Day82 #Java #BinaryTree #DFS #Recursion #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟴𝟲/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟳𝟮𝟰. 𝗙𝗶𝗻𝗱 𝗣𝗶𝘃𝗼𝘁 𝗜𝗻𝗱𝗲𝘅 | 🟢 𝗘𝗮𝘀𝘆 | 𝗝𝗮𝘃𝗮 Deceptively simple — and a perfect introduction to the prefix sum pattern. 𝗧𝗵𝗲 𝗽𝗿𝗼𝗯𝗹𝗲𝗺: Find the index where the sum of all elements to the left equals the sum of all elements to the right. 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗣𝗿𝗲𝗳𝗶𝘅 𝗦𝘂𝗺: ✅ Compute the total sum in one pass ✅ Track leftTotal as we iterate ✅ rightTotal = total - leftTotal - nums[i] ✅ If leftTotal == rightTotal → pivot found! No extra arrays. No nested loops. Just one pre-computation and one clean scan. 𝗧𝗵𝗲 𝗸𝗲𝘆 𝗶𝗻𝘀𝗶𝗴𝗵𝘁: Instead of recalculating both sides at every index, derive the right sum from what you already know — total and left. That drops it from O(n²) to O(n) instantly. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: ⏱ Time: O(n) — two passes 📦 Space: O(1) This pattern — precompute total, derive the other side on the fly — shows up everywhere: product arrays, equilibrium points, range queries. A must-know! 🧠 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/g_E5Ahfe 14 more days. The finish line is in sight! 💪 #LeetCode #Day86of100 #100DaysOfCode #Java #DSA #PrefixSum #Arrays #CodingChallenge #Programming
To view or add a comment, sign in
-
🚀 DSA Practice – Longest Subarray with Sum = K (Positive Numbers) Today I practiced a classic Sliding Window / Two Pointer problem. Problem: Find the longest subarray whose sum equals K, when the array contains only positive numbers. 💡 Key Idea: * Since all numbers are positive, we can use the sliding window technique: Expand the window by moving the right pointer. * If the sum becomes greater than k, shrink the window using the left pointer. Whenever sum == k, update the maximum length. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) Example: arr = [1, 2, 3, 1, 1, 1, 1, 4, 2, 3] k = 3 Longest subarray: [1, 1, 1] Length = 3 This problem is a great example of how understanding constraints (positive numbers) allows us to replace complex approaches like HashMap + Prefix Sum with a simpler and more efficient Sliding Window technique. #DSA #Algorithms #Java #SlidingWindow #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Day: 73/365 📌 LeetCode POTD: Minimum Absolute Difference in Sliding Submatrix Medium Key takeaways/Learnings from this problem: 1. This problem shows how sliding window ideas extend to 2D, not just arrays, but it gets trickier to manage. 2. Maintaining a sorted structure (like multiset) helps in quickly finding min absolute differences in each window. 3. Big learning: brute force over every submatrix is too slow, so optimize by reusing previous window computations. 4. Overall, it’s a solid mix of 2D traversal + smart data structures to keep things efficient. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 Day 539 of #750DaysOfCode 🚀 Today I solved Determine Whether Matrix Can Be Obtained By Rotation (LeetCode 1886) using Java. 🔹 Problem Summary: Given two n × n binary matrices mat and target, we need to check whether mat can be converted into target by rotating it in 90-degree clockwise steps (0°, 90°, 180°, or 270°). 🔹 Approach Used: I followed a simple simulation approach: • Check if the current matrix equals target • If not, rotate the matrix by 90° clockwise • Repeat this up to 4 times • If any rotation matches, return true For rotation, I used the formula: new[j][n − 1 − i] = mat[i][j] This allowed me to generate the rotated matrix cleanly and compare it with the target. 🔹 Key Concepts Learned: ✅ Matrix rotation (90° clockwise) ✅ Matrix comparison ✅ Simulation approach ✅ Working with 2D arrays in Java ✅ Writing clean helper functions Practicing matrix problems daily is improving my understanding of transformations and indexing logic. #750DaysOfCode #Day539 #LeetCode #Java #DSA #Algorithms #CodingChallenge #Matrix #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding the maximum product subarray. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Maximum Product Subarray 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Tracked two values at each step: • Current maximum product • Current minimum product • Why both? • A negative number can turn a small product into a large one • For each element: • Calculated new max and min using previous values • Updated the result with the maximum product found 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Negative numbers can flip the result completely • Tracking both max and min is crucial • DP can be optimized using variables instead of arrays • Edge cases (like zero) reset the product 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sometimes the minimum value is just as important as the maximum — because it might become the next maximum. 53 days consistent 🚀 On to Day 54. #DSA #Arrays #DynamicProgramming #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 37/100 🚀 | #100DaysOfDSA Solved Reverse String by Character Type – LC 3823 This problem required reversing characters in a string — but with a twist. Letters and special characters had to be reversed within their own groups while keeping their original positions relative to each other. Example idea: Letters reverse among letters, special characters reverse among specials. My Approach: • Converted the string to a character array for easier traversal. • Used two stacks — one for letters and one for special characters. • First pass: pushed characters into their respective stacks. • Second pass: rebuilt the string by popping from the correct stack depending on the character type. Time Complexity: O(n) Space Complexity: O(n) Key Learning: Breaking a problem into categories can simplify the logic significantly. Once characters were separated by type, reconstructing the result became straightforward. Small problems. Clear thinking. Consistent progress. 💪 #100DaysOfCode #LeetCode #DSA #Java #Strings #Stacks #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 20/100: The "Cheat Code" for String Rotations 🔄 I’m back on the grind! Today’s challenge was checking if one string is a rotation of another (e.g., "waterbottle" and "erbottlewat"). The Strategy: Instead of writing complex loops to shift characters, I used the Concatenation Trick: 1️⃣ Check if lengths are equal. 2️⃣ Create a new string by adding the first string to itself (s1 + s1). 3️⃣ Check if the second string exists inside that combined string. It’s a simple, elegant O(n) solution that shows how sometimes "working smarter" with data structures beats "working harder" with loops. 20% of the way there. Let's keep moving! 🚀 #100DaysOfCode #Java #DSA #Strings #ProblemSolving #Unit2 #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Day 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 11 Today’s focus: Sliding Window with distinct element constraints. Problem solved: • Subarrays with K Different Integers (LeetCode 992) Concepts used: • Sliding Window / Two-pointer technique • Frequency tracking using HashMap • Counting subarrays using window expansion Key takeaway: The goal of this problem is to count the number of subarrays that contain exactly K distinct integers. A useful trick here is to break the problem into two parts: Subarrays with exactly K distinct = Subarrays with at most K distinct − Subarrays with at most (K−1) distinct Using a sliding window, we maintain a window that contains at most K distinct elements. A frequency map keeps track of how many times each element appears in the current window. As the window expands, if the number of distinct elements exceeds K, we shrink the window from the left until the condition is satisfied again. At each step, the number of valid subarrays ending at the current index can be counted efficiently, allowing the entire problem to be solved in O(n) time. Continuing to strengthen pattern recognition and consistency in solving DSA problems. #DSA #Java #LeetCode #CodingJourney
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