🚀 Day 80/100 – Word Search 🧠 Problem: Given a 2D grid of characters and a word, return true if the word exists in the grid. ✔️ You can move: up, down, left, right ❌ You cannot reuse the same cell 💡 Core Idea This problem is solved using Backtracking + DFS 🔥 1️⃣ Start from every cell in the grid 2️⃣ If the first character matches → start DFS 3️⃣ Explore all 4 directions 4️⃣ Mark the cell as visited (temporarily) 5️⃣ Backtrack by restoring the original value 👉 Match → Explore → Mark → Undo 📚 Key Learnings Depth First Search (DFS) on grid Backtracking with visited marking Handling constraints in matrix problems ⏱️ Complexity Time Complexity: O(m × n × 4^L) (L = length of word) Space Complexity: O(L) #100DaysOfCode #Day80 #LeetCode #DSA #Backtracking #DFS #Matrix #Algorithms #ProblemSolving #CodingJourney #Consistency
Word Search in 2D Grid using Backtracking and DFS
More Relevant Posts
-
Word Search Using Backtracking on Grid 🧩 Day 12 👈 The challenge is to check if a word exists in a grid by moving in 4 directions (up, down, left, right) without revisiting the same cell. 💡 Key learnings: 👉 This is a DFS + Backtracking problem 👉 Start from every cell matching the first character 👉 Explore all 4 directions recursively 👉 Mark visited cells temporarily to avoid reuse Approach: 👉 Traverse the grid 👉 When a match is found, start DFS 👉 Move in all possible directions 👉 Backtrack by restoring the cell value #DSA #Backtracking #DFS #Matrix #Algorithms #CodingJourney #LeetCode #ProblemSolving #InterviewPreparation #SoftwareEngineer
To view or add a comment, sign in
-
-
🚀 Day 83/100 – Subsets II 🧠 Problem: Given an integer array that may contain duplicates, return all possible subsets (power set). ⚠️ The solution set must not contain duplicate subsets 💡 Core Idea This is Backtracking + Duplicate Handling 🔥 1️⃣ First sort the array 2️⃣ Use Pick / Not Pick approach 3️⃣ While skipping elements → avoid duplicates: 👉 Skip all same elements using a loop 4️⃣ Build subsets recursively 👉 Key trick: Skip duplicates carefully 📚 Key Learnings Handling duplicates in recursion Importance of sorting Avoiding redundant subsets ⏱️ Complexity Time Complexity: O(2ⁿ) Space Complexity: O(n) #100DaysOfCode #Day83 #LeetCode #DSA #Backtracking #Recursion #Subsets #Algorithms #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
16 Apr.2k26✅ Covered Today : ML - Decision Trees - • Hyper Parameter Tuning • Handwriting Classifier • Regression Trees • CF Q1 - Calculating Function • CF Q2 - Zero Array #CodeForces #MachineLearning #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Day 87/100 – 4Sum 🧠 Problem: Given an array of integers, return all unique quadruplets [a, b, c, d] such that: 👉 a + b + c + d = target ✔️ No duplicate quadruplets ✔️ Order doesn’t matter 💡 Core Idea Extension of 3Sum → 4Sum 👉 Sort the array 👉 Fix two elements (i, j) 👉 Use two pointers (left, right) 🔥 Key Trick: Skip duplicates at every step to avoid repeated quadruplets 📚 Key Learnings 1. Two pointer optimization 2. Handling duplicates carefully 3. Reducing nested loops using sorting ⏱️ Complexity Time Complexity: O(n³) Space Complexity: O(1) (excluding output) #100DaysOfCode #Day87 #LeetCode #DSA #TwoPointers #Algorithms #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 89/100 – Permutations II 🧠 Problem: Given an array that may contain duplicates, return all unique permutations ✔️ No duplicate permutations ✔️ Order doesn’t matter 💡 Core Idea 🔥 Classic Backtracking + Duplicate Handling 👉 Sort the array first 👉 Use a used[] array 👉 Skip duplicates using condition: if(i > 0 && nums[i] == nums[i-1] && !used[i-1]) continue; ⚡ This ensures only unique permutations are generated 📚 Key Learnings Backtracking with pruning Handling duplicates efficiently Importance of sorting before recursion ⏱️ Complexity Time Complexity: O(n! ) Space Complexity: O(n) #100DaysOfCode #Day89 #LeetCode #DSA #Backtracking #Algorithms #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 81/100 – Reverse Integer 🧠 Problem: Given a signed 32-bit integer x, return the integer formed by reversing its digits. ⚠️ If reversing causes the value to go outside the 32-bit signed integer range → return 0 💡 Core Idea This is a simple digit extraction and reconstruction problem 🔥 1️⃣ Extract last digit → digit = x % 10 2️⃣ Append to result → ans = ans * 10 + digit 3️⃣ Remove last digit → x = x / 10 4️⃣ Before adding → check for overflow 👉 Build the reversed number step by step 📚 Key Learnings Digit manipulation Handling integer overflow carefully Writing clean iterative logic ⏱️ Complexity Time Complexity: O(log₁₀ n) Space Complexity: O(1) #100DaysOfCode #Day81 #LeetCode #DSA #Math #Implementation #Algorithms #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 213 of #300DaysOfCoding Today’s problem: Minimum Distance to the Target Element 🧠 Key Insight: Instead of overthinking, I focused on a simple linear scan: Traverse the array Check where the target exists Compute the minimum distance using abs(i - start) ✨ Sometimes, the simplest approach is the most efficient one! 💻 What I learned: Strengthened problem-solving with basic iteration Importance of clarity over complexity Practiced writing clean and optimal O(n) code ⚡ Takeaway: Not every problem needs advanced algorithms—strong fundamentals can solve a lot! #Day213 #300DaysOfCoding #DSA #CodingJourney #CPlusPlus #KeepLearning
To view or add a comment, sign in
-
-
Post 3 — Tabulation Approach DSA Journey Update: Learning Tabulation (Bottom-Up DP) 🎯 Today I explored Tabulation, a bottom-up approach in Dynamic Programming. Focus Areas: • Building solutions iteratively • Using DP tables • Eliminating recursion overhead Insight: Tabulation provides better control over space and execution flow. Learning Outcome: ✅ Clear DP state understanding ✅ Improved iterative thinking Next: Solve classic DP problems like Fibonacci and Climbing Stairs. #DSA #DynamicProgramming #Tabulation #Algorithms 🚀
To view or add a comment, sign in
-
🚀 Day 49 of My DSA Journey 🔍 LeetCode Problem #212 – Word Search II Today’s problem was a challenging combination of Trie (prefix tree) and backtracking. The goal was to find all words from a given list that can be formed in a 2D board by connecting adjacent letters. 💡 Key Learning: Using Trie helps optimize the search by pruning unnecessary paths early instead of checking each word separately. ⚡ Insight: Combining DFS with Trie significantly reduces time complexity compared to brute force approaches. 📌 Takeaway: Advanced data structures like Trie can make a huge difference when dealing with multiple string searches. Consistency continues — Day 49 💪 #Day49 #LeetCode #DSA #Trie #Backtracking #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 8 of My LeetCode Journey Solved today’s problem: Detect Cycles in 2D Grid ✅ A classic graph problem involving DFS and cycle detection! 🔹 Problem Insight: Given a grid of characters, detect whether a cycle exists where adjacent cells have the same value. 🔹 Approach: • Treated the grid as a graph • Used DFS traversal to explore connected components • Tracked the previous cell to avoid false cycles • Detected a cycle if a visited cell is reached again (not the parent) 🔹 Complexity: • Time Complexity: O(m × n) • Space Complexity: O(m × n) 🧠 Key Learning: Cycle detection in grids is similar to graphs—tracking the parent node is crucial to avoid incorrect cycle detection. 📊 Today’s Stats: ✅ Runtime: 19 ms (Beats 78.50%) ✅ Memory: 70.92 MB (Beats 43.74%) Understanding graphs step by step 🚀 #LeetCode #DSA #Graph #DFS #CodingJourney #Consistency
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
Finally a puzzle where revisiting cells feels like trying to remember where you left keys.