LeetCode Word Search with DFS and Backtracking

🧠 Day 38 / 100 – DSA Practice Solved Word Search on LeetCode 🔍✅ 🔹 Problem: Given a 2D grid of characters and a word, check if the word exists in the grid by traversing adjacent cells (horizontally or vertically). 🔹 Approach: Used DFS + Backtracking: Start from each cell Explore all 4 directions (up, down, left, right) Mark visited cells to avoid reuse Backtrack if the path doesn’t match 🔍 Key Insight: Backtracking helps explore all possible paths while ensuring each cell is used only once per path 🔹 Complexity: ⏱ Time → O(m × n × 4^L) 📦 Space → O(L) recursion stack 💯 Result: ✔️ All test cases passed ⚡ Runtime: 130 ms (Beats 73%) Great problem to strengthen DFS & Backtracking concepts 🚀 #Day38 #100DaysOfCode #LeetCode #Java #DSA #Backtracking #DFS #Algorithms #CodingJourney

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories