✨ Day 85 of #100DaysOfCode ✨ Today I worked on the Word Search problem using C++ and Backtracking. In this problem, we’re given a 2D grid of characters and need to check if a given word can be formed by sequentially adjacent letters (up, down, left, or right). 🔹 My approach: Start from every cell that matches the first character of the word. Use recursion to explore all four directions — top, right, bottom, and left. Temporarily mark a cell as visited (using ‘!’) to prevent revisiting it during the same search path. If we reach the end of the word, we return true. After exploring, we backtrack by restoring the cell’s original value. This solution is a great example of depth-first search (DFS) combined with backtracking — a powerful pattern for solving grid-based problems. 💡 Key Concepts Used: Recursion Backtracking 2D Array Traversal Boundary Condition Handling #100DaysOfCode #DSA #CPlusPlus #Backtracking #Recursion #ProblemSolving #CodeNewbie #CodingJourney
Shivam Yadav’s Post
More Relevant Posts
-
Today I solved the Reverse Integer problem on LeetCode — a classic challenge that tests how well you handle numeric operations and overflow conditions in a constrained environment. 🧩 Problem Summary: Given a signed 32-bit integer x, return the integer obtained by reversing its digits. If reversing x causes it to go outside the 32-bit signed integer range [-2³¹, 2³¹ - 1], return 0. ⚙️ Approach: Initialize revNum = 0 to store the reversed number. Extract the last digit of n using dig = n % 10. Before updating, check for overflow: If revNum > INT_MAX / 10 or revNum < INT_MIN / 10, return 0. Append the digit: revNum = revNum * 10 + dig. Remove the last digit from the original number: n = n / 10. Continue until all digits are processed. Return the final reversed integer. This ensures safety against integer overflow without using 64-bit integers — a key constraint of the problem. ⏱️ Time Complexity: O(log₁₀(n)) → Each iteration processes one digit. 💾 Space Complexity: O(1) → Constant extra space used. 🧠 Concepts Practiced: Integer manipulation Overflow handling Edge case analysis Bit-width constraints #LeetCode #Cplusplus #DSA #ProblemSolving #CodingJourney #CodeWithConsistency #Programming #Learning
To view or add a comment, sign in
-
-
📅 October 29, 2025 🧩 Problems Solved: 🔹 House Robber III | Binary Tree, DFS, Dynamic Programming | Medium The key to simplifying this problem is to return two states for every node: 1️⃣ The maximum sum including the current node. 2️⃣ The maximum sum excluding the current node. At each recursive call: For the include case, we add the node’s value plus the sums of left and right subtrees excluding their roots. For the exclude case, we take the maximum of both states from the left and right subtrees, since we can freely choose whether to include or skip them. Finally, the answer is the maximum between the include and exclude sums at the root. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) https://lnkd.in/gSqTztRw 💡 Key Takeaways: • Always think in “states” when dealing with tree DP — defining clear include/exclude relationships often simplifies recursive logic. • Returning multiple values (as a pair or struct) from recursion can greatly reduce redundant recomputation and improve clarity. #LeetCode #100DaysOfCode #DSA #CodingJourney #Cplusplus #ProblemSolving #TechPrep #BinaryTree #DynamicProgramming
To view or add a comment, sign in
-
-
🚀 Day 3 of 100 Days of DSA Challenge Today I solved a problem based on counting frequencies of elements in an array using C++ STL 🧠 This problem helped me understand how efficiently we can use data structures like unordered_map and vector of vectors to store and organize data. 💡 Key Learnings: How to count the frequency of each element using an unordered_map<int, int>. How to convert map data into a 2D vector (vector<vector<int>>) format. The difference between map and unordered_map in terms of ordering and time complexity. Importance of using modern C++ features like structured bindings (auto &[key, value]) for clean and readable code. Example Input: [1, 2, 2, 3, 3, 3] Output: [[1, 1], [2, 2], [3, 3]] Every problem adds a new tool to the toolkit — and consistency builds confidence 💪 #100DaysOfCode #Day3 #LeetCode #DSA #CPlusPlus #ProblemSolving #CodingChallenge #LearnByDoing #CodeEveryday #SoftwareDeveloper #STL
To view or add a comment, sign in
-
-
🚀 #Day57 of #100DaysOfLeetCodeHard 📘 Problem: [LeetCode 2547 – Minimum Cost to Split an Array] My Submission:https://lnkd.in/gB2aQ9TS This one was a really interesting DP + preprocessing problem that tested both efficiency and clarity of thought. 💡 Approach: The key idea was to precompute the cost of every possible subarray [i...j], where cost represents the number of elements that appear more than once (the trimmed part). Once precomputed, the problem transforms into a simple Dynamic Programming formulation: dp[i] = min( k + cost[i][j] + dp[j+1] ) for all j ≥ i This way, we can efficiently find the optimal points to split the array, minimizing the total cost. Given the constraints (n ≤ 1000), an O(n²) preprocessing and DP approach works perfectly. 🧮 Complexity: Time: O(n²) Space: O(n²) A neat problem that beautifully combines frequency tracking, preprocessing, and classic DP — a great example of how strong intuition can simplify what initially looks intimidating. #100DaysOfLeetCodeHard #Day57 #LeetCode #DynamicProgramming #ProblemSolving #DSA #CompetitiveProgramming #Precomputation
To view or add a comment, sign in
-
-
Bonus: Deep Understanding of PEDMAS rule will help you know how Programming and how Scripting can be developed. NB: Keyphrase: Order of Operations.
To view or add a comment, sign in
-
-
🌟Day 59 LeetCode: Subsets (78) Approach: Used backtracking to generate all possible subsets of a given array by exploring inclusion and exclusion of each element. ✨ Learned how recursion and backtracking can systematically explore all combinations — a classic and insightful problem! 📈 Improved understanding of recursion tree logic, subset generation, and backtracking techniques in C++. #LeetCode #100DaysOfCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #CodeEveryday
To view or add a comment, sign in
-
-
3461. Check If Digits Are Equal in String After Operations I 🧩 LeetCode Problem of the Day — Solved! 🔗 Solution Link: https://lnkd.in/gRdq2P9M Today’s Problem of the Day was quite easy — just needed to carefully follow the steps described in the question. The task was to repeatedly combine consecutive digits by summing them modulo 10 until only two digits remained, and then check if they’re equal. 🧠 Key Idea: Iterate over the string and compute new digits as (s[i] + s[i+1]) % 10. Continue until only two digits are left. Return true if both digits are equal, else false. 🕒 Complexity: Time: O(n²) (due to repeated reductions) Space: O(1) 💡 Takeaway: Sometimes the simplest problems remind us that precise implementation and attention to detail matter as much as complex logic. #LeetCode #ProblemOfTheDay #DSA #CodingJourney #Consistency #EasyProblem #Implementation
To view or add a comment, sign in
-
-
🍁Day 68 LeetCode: Reverse Linked List (206) Approach: Reversed the linked list iteratively by updating pointers step-by-step while traversing through the list. ✨ Learned how pointer manipulation can transform linked list structures efficiently — a fundamental and must-know problem! 📈 Improved understanding of linked lists, pointer handling, and iterative logic in C++. #LeetCode #100DaysOfCode #DSA #LinkedList #Pointers #ProblemSolving #CodingJourney #CodeEveryday
To view or add a comment, sign in
-
-
LeetCode 2965: Find missing and repeated values 🔍 Imagine you have a grid filled with numbers. Each number from 1 to n² should appear exactly once, but one number appears twice (repeated), and one is missing. How does the code work? - Use a Counter (like a tally sheet) to count how many times every number appears across the grid. - Go through every number in the grid and update their counts. Now, check: - If any number appears twice, save it as the repeated number. - Then, check from 1 to n², and if any number isn’t in the counter, that’s the missing one. - Return both the repeated and the missing numbers as your answer. Complexity: - Time Complexity: O(n²) — Scan every cell twice (once for counting, once for checking). - Space Complexity: O(n²) — Needed for the counter. Let’s use a counter, check every corner, and spot both the mistake and the missing card! Check out the problem here: https://lnkd.in/g6549Q_f Keep going, keep revising, and keep building confidence! 💪🔥 #DSA #Coding #ProblemSolving #Learning
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