🔥 DSA Challenge – Day 130/360 🚀 📌 Topic: Backtracking / DFS on Grid 🧩 Problem: Word Search Problem Statement: Given a 2D grid of characters and a word, check if the word exists by moving in 4 directions (no cell reuse). 🔍 Example: Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]] word = "ABCCED" Output: true 💡 Approach: Backtracking + DFS 1️⃣ Step 1 – Start from every cell matching the first character 2️⃣ Step 2 – Explore 4 directions (up, down, left, right) recursively 3️⃣ Step 3 – Mark visited cells and backtrack after exploring ✔️ Avoid revisiting the same cell ✔️ Stop early when characters don’t match ✔️ Return true as soon as full word is found ⏱ Complexity: Time: O(N * M * 4^L) Space: O(L) (recursion stack) 📚 Key Learning: Backtracking is powerful for exploring all possible paths while avoiding invalid ones using pruning. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #130DaysOfCode #LeetCode #Backtracking
Dileep Kumar Maurya’s Post
More Relevant Posts
-
🔥 DSA Challenge – Day 131/360 🚀 📌 Topic: Backtracking / Recursion 🧩 Problem: N-Queens Problem Statement: Place N queens on an N×N chessboard such that no two queens attack each other. 🔍 Example: Input: n = 4 Output: [[".Q..","...Q","Q...","..Q."], ["..Q.","Q...","...Q",".Q.."]] 💡 Approach: Optimized Backtracking (Hashing) 1️⃣ Step 1 – Try placing a queen column by column 2️⃣ Step 2 – Use arrays to check if row & diagonals are safe in O(1) 3️⃣ Step 3 – Place queen → recurse → backtrack if needed ⏱ Complexity: Time: O(N!) Space: O(N) + recursion stack 📚 Key Learning: Using hashing for rows & diagonals avoids repeated checks and makes backtracking much faster ⚡ #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #131DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 126/360 🚀 📌 Topic: Array + Backtracking (Recursion) 🧩 Problem: Combination Sum II Problem Statement: Find all unique combinations in an array where numbers sum up to a target. Each number can be used only once, and duplicate combinations are not allowed. 🔍 Example: Input: candidates = [10,1,2,7,6,1,5], target = 8 Output: [[1,1,6], [1,2,5], [1,7], [2,6]] 💡 Approach: Backtracking + Pruning 1️⃣ Step 1 – Sort the array to handle duplicates easily 2️⃣ Step 2 – Use recursion to pick elements and reduce target 3️⃣ Step 3 – Skip duplicates & backtrack after each recursive call 👉 Use condition to skip duplicates: if(i > ind && arr[i] == arr[i-1]) continue; 👉 Stop early if element exceeds target (pruning) ⏱ Complexity: Time: O(2^n) Space: O(k * x) (for storing combinations) 📚 Key Learning: Sorting + duplicate skipping is the key trick to avoid repeated combinations in backtracking problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 127/360 🚀 📌 Topic: Backtracking 🧩 Problem: Subsets II Problem Statement: Given an integer array that may contain duplicates, return all possible subsets such that the solution set does not contain duplicate subsets. 🔍 Example: Input: nums = [1,2,2] Output: [[], [1], [1,2], [1,2,2], [2], [2,2]] 💡 Approach: Backtracking + Sorting 1️⃣ Step 1 – Sort the array to group duplicate elements together 2️⃣ Step 2 – Use recursion to generate all subsets 3️⃣ Step 3 – Skip duplicate elements using condition (i != ind && nums[i] == nums[i-1]) ⏱ Complexity: Time: O(2^n) Space: O(n) (recursion stack + subset storage) 📚 Key Learning: Sorting + smart skipping of duplicates helps avoid repeated subsets in backtracking problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 120/360 🚀 📌 Topic: Math + Recursion 🧩 Problem: Count Good Numbers Problem Statement: Count total valid numbers of length n where even indices have 5 choices and odd indices have 4 choices. 🔍 Example: Input: n = 4 Output: 400 💡 Approach: Optimized (Binary Exponentiation) 1️⃣ Step 1 – Count even positions → use (n + 1) / 2 2️⃣ Step 2 – Count odd positions → use n / 2 3️⃣ Step 3 – Compute power using fast exponentiation and multiply ✔ Use formula: 5^(ceil(n/2)) × 4^(floor(n/2)) ✔ Apply modulo to handle large numbers ✔ Use recursion to reduce time complexity ⏱ Complexity: Time: O(log n) Space: O(log n) 📚 Key Learning: Binary Exponentiation helps reduce power calculation from O(n) to O(log n), which is very useful in large constraints problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode
To view or add a comment, sign in
-
-
🚀 DSA Journey – Day 4-8 After learning loops and pattern problems, I moved to the next core topic — Arrays. 💡 Why Arrays Matter: Arrays are the foundation of most DSA problems. They are heavily used in: • Searching & Sorting • Sliding Window & Two Pointers • Dynamic Programming • Real-world systems (data storage & processing) 📚 Problems I Solved (Striver A2Z + NeetCode): • Find Maximum & Minimum Element • Check if Array is Sorted • Reverse an Array • Second Largest Element • Move Zeros to End • Remove Duplicates from Sorted Array • Two Sum 🧠 Array Cheatsheet (Beginner Friendly): ✔ Traversal → Always start with a loop (O(n)) ✔ Max/Min → Keep a variable and update while traversing ✔ Reverse → Use two pointers (start & end) ✔ Duplicates → Use two pointers / set ✔ Two Sum → Use HashMap for O(n) optimization ⚡ Common Mistakes to Avoid: • Ignoring edge cases (empty array, single element) • Writing O(n²) when O(n) is possible • Not dry running before coding • Forgetting index-based thinking 🧠 What I Learned: • How to shift from brute force → optimized approach • Importance of time complexity in interviews • Same pattern can solve multiple problems 📌 Takeaway: If you master arrays, you unlock 50% of DSA problem-solving patterns. #DSA #Arrays #ProblemSolving #Java #CodingJourney
To view or add a comment, sign in
-
-
Growth in DSA is not just about understanding problems, but about applying that understanding to solve them. Day 36/100 — Data Structures & Algorithms Journey After spending time learning the intuition behind Trapping Rain Water, today I focused on actually solving it. This problem pushed me to combine visualization with logic and apply an optimized approach. Instead of brute force, I used the Two Pointer technique to efficiently calculate the trapped water. Today’s Focus: Applying Two Pointer approach to a complex problem Using left max and right max concepts effectively Translating understanding into working code Improving problem-solving confidence Why this matters? Because solving a problem after deeply understanding it builds real confidence and clarity. Key Takeaways: Understanding + Implementation = Mastery Optimized thinking reduces time and space complexity Complex problems become manageable with the right approach Consistency in practice leads to improvement From learning → to understanding → to solving 🚀 #Day36 #DSA #LeetCode #ProblemSolving #SoftwareEngineering #CodingJourney #100DaysOfCode #TechLearning #DeveloperJourney #Programming #Python #InterviewPreparation #CodingSkills #ComputerScience #FutureEngineer #TechCareers #SoftwareDeveloper #LearnInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 74 – DSA Journey | Valid Parentheses using Stack Continuing my daily DSA practice, today I solved a classic problem that strengthened my understanding of stacks and their real-world use in validating expressions. 📌 Problem Practiced: Valid Parentheses (LeetCode 20) 🔍 Problem Idea: Given a string containing different types of brackets, determine whether the input string is valid. A string is valid if brackets are closed in the correct order and type. 💡 Key Insight: Instead of manually checking pairs, a stack helps track opening brackets and ensures every closing bracket matches the most recent unmatched opening one. 📌 Approach Used: • Traverse the string from left to right • Push all opening brackets onto the stack • When encountering a closing bracket: – Check if the stack is empty → invalid – Pop the top element and verify if it matches • If any mismatch occurs → return false • At the end, the stack should be empty for a valid string 📌 Concepts Strengthened: • Stack data structure • LIFO (Last In First Out) principle • Bracket matching logic • Handling edge cases efficiently ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) 🔥 Today’s takeaway: Stacks are extremely useful for pattern validation problems — especially when dealing with nested or ordered structures like parentheses. On to Day 75! 🚀 #Day74 #DSAJourney #LeetCode #Stack #Java #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Every new pattern in DSA changes the way you look at problems. Day 41/100 — Data Structures & Algorithms Journey Today I worked on Longest Substring Without Repeating Characters, and it helped me understand the Sliding Window technique in a deeper way. Instead of checking all substrings, I learned how to dynamically adjust a window and maintain unique characters efficiently. Today’s Focus: Applying Sliding Window on strings Learning when to expand and shrink the window Managing duplicates using a set Improving time complexity from brute force to O(n) Why this matters? Because many real-world problems involve substrings and efficient traversal. Key Takeaways: Sliding Window avoids unnecessary re-computation Tracking elements efficiently is key Understanding window movement is crucial Optimized thinking leads to better solutions From brute force → to optimized thinking #Day41 #DSA #LeetCode #ProblemSolving #SoftwareEngineering #CodingJourney #100DaysOfCode #TechLearning #DeveloperJourney #Programming #Python #InterviewPreparation #CodingSkills #ComputerScience #FutureEngineer #TechCareers #SoftwareDeveloper #LearnInPublic #Consistency
To view or add a comment, sign in
-
-
#CodeEveryday — My DSA Journey | Day 4 🧩 Problem Solved: Word Search (LeetCode #79) 💭 What I Learned: Used DFS + backtracking to search for a word in a 2D grid by exploring all possible paths. At each step: ✔️ Checked boundary conditions and character match ✔️ Explored all 4 directions (up, down, left, right) ✔️ Marked the current cell as visited to avoid revisiting ✔️ Backtracked by unmarking the cell after exploration Ensured correctness by stopping early when a mismatch occurs or when the full word is found. This strengthened my understanding of grid traversal with constraints and path tracking. ⏱ Time Complexity: O(m × n × 4^L) (L = length of word) 🧠 Space Complexity: O(L) (recursion stack) ⚡ Key Takeaways: ✔️ Backtracking is essential for path-based problems in grids ✔️ Marking visited cells prevents cycles ✔️ Early stopping improves performance significantly 💻 Language Used: Java ☕ 📘 Concepts: DFS · Backtracking · Matrix Traversal · Recursion #CodeEveryday #DSA #LeetCode #Java #Backtracking #DFS #ProblemSolving #Algorithms #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
Day 1 of becoming DSA consistent (no excuses) Problem name : Minimum Distance Between Three Equal Elements II Difficulty : Medium Topic : Hash Table Most people would brute-force this problem… but there’s a smarter way using grouping. 🧠 Approach : 👉 Instead of comparing all triplets (which is slow), we optimize using a HashMap. Step 1: Store indices Traverse the array For each number, store all its indices in a map number → list of positions Step 2: Filter useful candidates Only consider numbers that appear at least 3 times Others cannot form a valid triplet Step 3: Check consecutive triplets For each list of indices: Pick 3 consecutive indices → (i, i+1, i+2) Since indices are sorted, this ensures minimum distance. Step 4: Compute distance, Distance is calculated between the 3 positions. Simplifies to: 2 × (last index − first index); Step 5: Track minimum. Keep updating the smallest distance found. If no valid triplet → return -1; Key Learning : When dealing with repeated elements: Use HashMap for grouping, Work on indices instead of values, Look for patterns (like consecutive grouping) to reduce complexity. IF YOU GUYS USED DIFFERENT LOGIC , Drop your logic below 👇... #leetcode #dsa #coding #softwareengineering #programming #interviewprep #java #grow #innovation #LetsConnect
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