🚀 Day 85 of #100DaysOfCode Today, I solved LeetCode 79 – Word Search, a classic problem that combines backtracking with grid traversal. 💡 Problem Overview: Given a 2D grid of characters and a word, the task is to determine if the word exists in the grid by forming it through sequentially adjacent cells (horizontal or vertical), without reusing any cell. 🧠 Approach: ✔️ Applied DFS with backtracking ✔️ Explored all possible paths starting from matching characters ✔️ Marked cells as visited during traversal and backtracked when needed ✔️ Ensured each cell is used only once per path ⚡ Key Takeaways: Backtracking is essential for exploring multiple possibilities DFS helps in exploring paths deeply Proper state management (visited/unvisited) is crucial 📊 Complexity Analysis: Time Complexity: O(n × m × 4^L) (L = length of word) Space Complexity: O(L) (recursion stack) Building strong recursion and backtracking skills 🚀 #LeetCode #100DaysOfCode #DSA #Backtracking #DFS #Recursion #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
Solved LeetCode 79 Word Search with Backtracking and DFS
More Relevant Posts
-
📱 LeetCode 17 – Letter Combinations of a Phone Number | Mastering Backtracking Solved a classic recursion problem today that perfectly demonstrates the power of backtracking and combination building. The challenge: given a string of digits (2–9), generate all possible letter combinations based on the traditional phone keypad mapping. 💡 Key Insight: Each digit maps to multiple characters, and the goal is to explore all possible combinations by picking one character from each digit. This naturally leads to a backtracking approach, where: We build combinations step by step Explore all possibilities recursively Backtrack to try different paths ⚙️ Approach: Use a mapping of digits → letters Traverse the input using recursion Append characters and move forward Store the result when a valid combination is formed 🚀 Complexity: Time: O(4ⁿ) Space: O(n) (recursion stack) 📌 What I learned: How to think in terms of recursion trees Efficiently generating combinations Writing clean and structured backtracking code Problems like this build a strong foundation for tackling advanced topics like DFS, recursion, and combinatorial algorithms. #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 73 of #100DaysOfCode 💻 Problem 39: Combination Sum ✅ Successfully solved on LeetCode! 🔍 Problem Summary: Given an array of distinct integers candidates and a target integer target, return all unique combinations where the chosen numbers sum to target. You can use the same number unlimited times. 🧠 Approach (Backtracking): • Explore all possible combinations recursively • Stop when sum exceeds target (pruning) • Store valid combinations when target becomes 0 • Reuse same element to allow unlimited picks ⚡ Key Insight: Backtracking helps efficiently generate combinations while avoiding unnecessary computations using pruning. 💡 What I Learned: • Strong grip on recursion + backtracking • How to reduce search space using pruning • Writing clean and optimized recursive solutions 🔥 73 days strong — consistency is paying off! #Day73 #100DaysOfCode #LeetCode #DSA #Backtracking #CodingJourney
To view or add a comment, sign in
-
-
Day 7 🚀 Solved: Balanced Binary Tree (LeetCode 110) This problem builds on recursion and tree depth. A tree is balanced if the height difference between left and right subtrees is at most 1 for every node. 💡 My approaches: 🔹 Approach 1 (Brute Force): For every node, calculate left and right subtree heights Check the difference and recurse further 🔹 Approach 2 (Optimal – Postorder DFS): Compute height and balance together in one traversal Avoid recomputing subtree heights 💡 Key learning: Instead of solving subproblems separately, combine them in a single DFS to optimize performance. ⏱️ Time Complexity: Brute Force → O(n²) Optimal → O(n) 🔗 GitHub: https://lnkd.in/gVdJeg2a #DSA #LeetCode #Coding
To view or add a comment, sign in
-
The Logic of Symmetry Day 242 Today Today is day 242 of my coding journey and I am focusing on the Two Pointer technique. This is a very efficient way to solve problems on linear data structures like arrays and strings. The main idea is to use two different indices to move through the data from different ends or at different speeds. I practiced the Opposite Direction pattern today. In this pattern one pointer starts at index zero and the other at the end of the array. They move toward each other until they meet. This logic is perfect for comparison problems like checking if a string is a palindrome or reversing a string. Instead of using extra memory I can just swap or compare elements in place which makes the code much faster. I also worked on the Squares of a Sorted Array problem where I compared values from both ends to build a new sorted list. The Valid Word Abbreviation problem was a great challenge because I had to synchronize two pointers across a word and its abbreviation while handling numbers carefully. Learning these patterns helps me see the logic behind the code instead of just memorizing solutions. LeetCode questions I solved today: LeetCode 125 Valid Palindrome LeetCode 344 Reverse String LeetCode 977 Squares of a Sorted Array LeetCode 680 Valid Palindrome II LeetCode 408 Valid Word Abbreviation #DSAinJavaScript #365daysOfCoding #JavaScriptLogic #LeetCodeDaily #TwoPointers #ProblemSolving #AlgorithmPractice #LogicBuilding #CodingJourney #SoftwareDeveloper #WebDevelopment #DataStructures #JSAlgorithms #CleanCode #TechLearning #ProgrammingGoals #MERNStack #DailyCoding #FullStackDeveloper #CodingCommunity
To view or add a comment, sign in
-
🔥 Day 173 of My LeetCode Journey Problem 113: Path Sum II 💡 Problem Insight: Today’s problem extends Path Sum — instead of just checking existence, you must return all root-to-leaf paths whose sum equals the target. This shift from a Boolean list makes the problem more complex. 🧠 Concept Highlight: The solution uses DFS + backtracking: Traverse the tree while maintaining the current path Subtract node values from the target sum When a valid leaf is reached, store the path Backtrack to explore other possibilities Backtracking is essential to avoid mixing paths. 💪 Key Takeaway: Whenever a problem asks for all possible paths/combinations, backtracking is the go-to technique. Managing state correctly is more important than traversal itself. ✨ Daily Reflection: This problem reinforced the need for discipline when storing results. Without proper backtracking, solutions become incorrect quickly. #Day173 #LeetCode #BinaryTree #DFS #Backtracking #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Today, I solved LeetCode 290 – Word Pattern, a problem that focuses on pattern matching and mapping relationships. 💡 Problem Overview: Given a pattern and a string, the task is to determine if the string follows the same pattern, ensuring a one-to-one mapping between characters in the pattern and words in the string. 🧠 Approach: To solve this problem efficiently, I focused on: ✔️ Using a hashmap to map pattern characters to words ✔️ Ensuring a bijection (one-to-one mapping) between pattern and words ✔️ Validating consistency throughout the traversal This approach ensures correctness while maintaining simplicity. ⚡ Key Takeaways: Hashmaps are powerful for mapping relationships Ensuring bijection is crucial in pattern problems Clean validation logic avoids edge-case errors 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Building strong fundamentals one problem at a time 🚀 #LeetCode #100DaysOfCode #DSA #HashMap #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Today I solved "Path Sum III" on LeetCode using a DFS + Recursion approach. Key Idea: We need to count all paths where the sum of node values equals the target. The path doesn’t have to start from the root — it can start from any node! Approach: • For every node, treat it as a starting point • Use DFS to explore all downward paths • Reduce the target at each step (target - node->val) • If a node matches the remaining target → count it • Repeat the process for left and right subtrees Why this works: Every node gets a chance to act as the starting point, and DFS ensures we explore all possible paths efficiently. Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Backtracking (implicit) Time Complexity: O(n²) in worst case Space Complexity: O(h) This problem helped me understand how to explore all possible paths in a tree, not just root-based ones — a big step forward in mastering tree problems From single path problems → to handling multiple dynamic paths… growing every day #Day90 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
Day 97/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 456 – 132 Pattern(Medium) 🧠 Approach: Traverse the array from right to left while maintaining a stack. Use a variable to track the “middle” element (the ‘2’ in 132 pattern) and check if a valid pattern exists. 💻 Solution: class Solution: def find132pattern(self, nums: List[int]) -> bool: stack = [] third = float('-inf') for i in range(len(nums) - 1, -1, -1): if nums[i] < third: return True while stack and nums[i] > stack[-1]: third = stack.pop() stack.append(nums[i]) return False ⏱ Time | Space: O(n) | O(n) 📌 Key Takeaway: Using a monotonic stack while iterating backwards helps efficiently detect complex patterns in linear time. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 79 of #100DaysOfCode Today, I solved LeetCode 32 – Longest Valid Parentheses, a challenging problem that focuses on stack-based logic and string processing. 💡 Problem Overview: Given a string containing only '(' and ')', the goal is to find the length of the longest valid (well-formed) parentheses substring. 🧠 Approach: ✔️ Used a stack-based approach to track indices ✔️ Initialized stack with -1 to handle edge cases ✔️ For every closing bracket, popped from stack ✔️ Calculated valid substring length using current index and stack top This approach efficiently tracks valid sequences and avoids reprocessing. ⚡ Key Takeaways: Stack is powerful for handling matching problems Index-based tracking simplifies substring calculations Handling edge cases (like invalid starting brackets) is crucial 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Solving hard problems step by step and improving every day 🚀 #LeetCode #100DaysOfCode #DSA #Stack #Strings #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep #HardProblems
To view or add a comment, sign in
-
-
🚀 Day 82 of #100DaysOfCode Today, I solved LeetCode 41 – First Missing Positive, a classic hard problem that tests in-place array manipulation and optimization. 💡 Problem Overview: Given an unsorted array, the goal is to find the smallest missing positive integer in O(n) time and O(1) space. 🧠 Approach: ✔️ Used index-based placement (cyclic sort idea) ✔️ Placed each number x at index x - 1 whenever possible ✔️ Ignored negative numbers and values out of range ✔️ Finally, scanned the array to find the first index where the value is incorrect This ensures optimal time and space complexity without using extra data structures. ⚡ Key Takeaways: In-place manipulation can eliminate the need for extra space Index mapping is a powerful trick for array problems Hard problems often rely on simple but clever observations 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) Solving challenging problems and strengthening core fundamentals 🚀 #LeetCode #100DaysOfCode #DSA #Arrays #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep #HardProblems
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