Day 25 | LeetCode Learning Journal 🚀 Today I tackled the classic N-Queens problem. If Day 12 was about patterns and counting, today was all about Backtracking and visualizing the recursion tree. Key Takeaways: Backtracking is Art: It’s not just about trying every possibility; it’s about "pruning" the branches that don't work early on to save time. The isSafe Logic: Writing a clean helper function to check rows, columns, and diagonals is the heart of this problem. It really tests your ability to think spatially in a grid. Debugging Recursion: Seeing that "Accepted" green text for a Hard/Medium-Hard backtracking problem hits different. It’s a sign that my ability to trace complex code is sharpening. "Consistency matters more than perfection." 25 days down—a quarter of the way through the 100-day mark! The problems are getting tougher, but the logic is becoming more intuitive. Excited to keep pushing deeper into advanced algorithms. #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #CPlusPlus #DSA #Backtracking #NQueens #LearningInPublic #KeepGrowing
LeetCode Day 25: N-Queens Problem Backtracking Solution
More Relevant Posts
-
Day 27 | LeetCode Learning Journal 🚀 Today I tackled Problem 40: Combination Sum II, and this one was a masterclass in the art of Backtracking. While Day 12 taught me the power of frequency mapping, today was all about managing state and avoiding duplicates. It’s fascinating how adding a single constraint—using each number only once—completely changes the strategy. It’s not just about finding a path to the target; it’s about efficiently pruning the search tree so you don't waste time on redundant calculations. Key takeaways from today: Sorting is Strategy: Sorting the input initially makes it much easier to skip duplicate elements during recursion. Pruning for Performance: Learning when to stop the recursion (if current > target) is the difference between a TLE (Time Limit Exceeded) and a 0ms runtime! 27 days in, and the "backtracking" mindset is finally starting to click. Seeing that 0ms (Beats 100%) result feels incredible—it's proof that clean logic beats brute force every time. #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #CPlusPlus #DSA #Backtracking #LearningInPublic #KeepGrowing
To view or add a comment, sign in
-
-
Day 28 | LeetCode Learning Journal 🚀 Today I tackled Problem 37: Sudoku Solver, and this one was a true test of patience and algorithmic thinking. Moving from simple patterns to complex backtracking has been a game-changer. It’s fascinating how recursion allows us to explore thousands of possibilities, "pruning" the ones that don't work and pivoting until we find the perfect solution. It’s not just about writing code; it’s about teaching the program how to make decisions. Key takeaways from today: Backtracking Mastery: Understanding how to "undo" a choice is as important as making one. Validation Logic: Breaking down constraints (rows, columns, and 3x3 grids) into clean, reusable functions. #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #CPlusPlus #DSA #Backtracking #LearningInPublic #KeepGrowing
To view or add a comment, sign in
-
-
🚀 Day 64 of LeetCode Problem Solving Journey — 100 Days LeetCode Challenge Today, I solved LeetCode #215 — Kth Largest Element in an Array using C++, under the guidance of Trainer NEKAL SINGH SALARIA Singh at REGex Software Services. 🔍 Problem Summary: Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest in sorted order, not the kth distinct element. 🧠 Approach Used (Sorting Method): I used the sorting approach to solve the problem: Sort the array in ascending order Traverse the array from the end (largest elements) Decrease k until reaching the kth largest element Return that value This approach is straightforward and easy to implement. 📚 Key Learnings of the Day ✔ Sorting helps quickly access ranked elements ✔ Traversing from the end simplifies finding largest values ✔ Always understand whether the problem requires distinct or non-distinct elements ✔ Simple approaches are good starting points before optimization ⏱ Complexity • Time Complexity: O(n log n) • Space Complexity: O(1) (ignoring sorting internals) 💡 Optimization Insight: The problem asks if we can solve it without sorting. A more optimal solution uses Quick Select or a Min Heap, which can reduce the time complexity to O(n) on average. Learning continues — see you on Day 65 🚀 #Day64 #100DaysLeetCodeChallenge #LeetCode #RegexSoftwareServices #NekalSingh #ProblemSolving #DSA #CPlusPlus #CodingChallenge #ProgrammingJourney #Arrays #KeepGrowing
To view or add a comment, sign in
-
-
🚀 Day 20 | 100 Days of Coding Challenge #DrGViswanathanChallenge 📘 Problem Solved: Letter Combinations of a Phone Number 🔧 Approach Used (Backtracking): • Used a hash map to store the mapping of digits (2–9) to their corresponding letters (like a phone keypad). • Started from the first digit and recursively generated combinations. • For each digit, tried all possible letters mapped to it. • Used backtracking (Choose → Explore → Undo) to build all valid strings. 📌 Algorithm Steps: Create a mapping of digits to letters. Traverse the input digits one by one. For each digit, append each possible letter to the current string. Move to the next digit recursively. When the string length equals the digits length, store the combination. ⏳ Complexity: Time: O(4ⁿ) (each digit can map to up to 4 letters) Space: O(n) recursion stack 🧠 Key Learning: Backtracking is ideal for problems where we need to generate all possible combinations. The Do → Recurse → Undo pattern helps systematically explore every possibility. 📂 Topics Covered: Backtracking, Recursion, Hash Map, String Combinations #100DaysOfCode #DSA #LeetCode #CPP #CodingJourney #Backtracking #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 21/120: Three weeks in. One problem. Zero shortcuts. One problem today. But it wasn't just any problem. Word Search Given a 2D board and a word, find if the word exists in the grid. You can move horizontally or vertically to adjacent cells, and you can't use the same cell twice in a single word. This is classic backtracking. And backtracking always looks simple until you actually implement it. The approach: for each cell, try to match the first character of the word. If it matches, recursively explore all four directions (up, down, left, right) to find the next character. Mark cells as visited to avoid reusing them. If a path doesn't work, backtrack - unmark the cell and try a different direction. Sounds straightforward. Implementation? Not so much. Getting the recursion right took multiple attempts. Base cases (word found, out of bounds, wrong character, already visited), recursive calls in all four directions, properly marking and unmarking cells during backtracking - each piece had to be perfect or the whole thing broke. I spent over an hour on this. Debugging backtracking is its own special kind of pain because you're dealing with state that changes as you explore and then reverts when you backtrack. One wrong flag and you either miss valid paths or count invalid ones. What this problem taught me: Backtracking is conceptually elegant - explore all possibilities, abandon dead ends, backtrack and try another path. But the devil is in the details. State management, proper cleanup after failed paths, avoiding infinite loops - it all matters. Three weeks down. 99 days to go. The journey continues. #DSA #CodingJourney #100DaysOfCode #LeetCode #GeeksForGeeks #Backtracking #Matrix #WordSearch #Recursion #Algorithms #SoftwareEngineering #Programming #Learning #Day21 #ThreeWeeks
To view or add a comment, sign in
-
-
Day 3 | LeetCode Learning Journal 🚀 Today I solved Combination Sum (Problem 39) on LeetCode another powerful backtracking problem. Compared to N-Queens, this one focused more on exploring combinations systematically while avoiding unnecessary paths. The interesting part was that we can reuse the same element multiple times, which changes how we design the recursive calls. The key learning was understanding how to: Keep track of the remaining target Use a start index to avoid duplicate combinations. Backtrack properly by removing the last added element after recursion .Instead of generating all possibilities blindly, I learned how pruning works if the current sum exceeds the target, we immediately stop exploring that path. This makes the solution much more efficient. 💡 🌱 What I learned: • How to generate combinations using recursion • Importance of pruning in backtracking • Managing state with push and pop operations • Thinking in terms of decision trees #LeetCode #100DaysOfCode #CodingJourney #Backtracking #DSA #Day3
To view or add a comment, sign in
-
-
Day 6 | LeetCode Learning Journal 🚀 Today I solved Palindrome Partitioning (Problem 131) on LeetCode. This problem was another strong backtracking challenge, but instead of focusing on sums or combinations, it focused on dividing a string into all possible palindromic partitions. The main challenge was checking palindromes efficiently while exploring every possible cut in the string. 🔑 Key Points: • Use backtracking to try every possible substring • Check if substring is palindrome before choosing it • If valid → push → recurse → pop • Base case when start index reaches string length • Carefully manage substring ranges (start to end) 🌱 What I Learned: • How to generate all possible partitions of a string • Combining recursion with condition checking (palindrome validation) • Difference between combination-style problems and partition-style problems • How recursion explores a decision tree of “cut” vs “don’t cut” • Strengthened understanding of backtracking patterns This problem really improved my clarity on how recursive partitioning works compared to problems like Combination Sum. The structure is similar, but the condition check (palindrome) changes the whole recursion flow. #LeetCode #100DaysOfCode #Backtracking #DSA #Day5 🚀
To view or add a comment, sign in
-
-
🚀 Day 36/100 – 3Sum (LeetCode 15) Today, I studied the 3Sum problem from the Apna College DSA Series by Shradha Ma’am and implemented the solution by solving LeetCode 15 – 3Sum. 📌 What I worked on today: • Understanding brute-force, better, and optimized approaches • Learning the two-pointer technique after sorting the array • Handling duplicate elements to avoid repeated triplets • Converting problem intuition into clean and efficient code 📌 Problem Solved: • LeetCode 15 – 3Sum 💡 Key Learning: Breaking the problem step by step and optimizing it gradually makes complex problems much easier to understand. This problem helped me improve my thinking around arrays, pointers, and edge cases. Watched the explanation first, then coded the solution myself in C++ using VS Code. Consistency over motivation 🚀 #DSA #CPP #Arrays #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #InterviewPreparation #Placements #BuildInPublic #LovelyProfessionalUniversity Shradha Khapra Apna College Amrendra Kumar Google LinkedIn Amazon
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge – Prime Number of Set Bits 📌 Problem: 762. Prime Number of Set Bits in Binary Representation 🔗 LeetCode Daily Question Today’s problem was simple on the surface—but a neat mix of bit manipulation + math. We’re given a range [left, right], and the task is to count numbers whose number of set bits (1s in binary) is prime. Brute force counting? Works—but needs optimization mindset. 💡 Key Insight: Use built-in bit count (popcount) to count set bits efficiently. Then check if that count belongs to a small set of prime numbers. Since max bits ≤ 20 → primes are limited → pre-store them. 🛠 Approach: • Loop from left → right • Count set bits using __builtin_popcount • Check if count is prime (using set lookup) • Increment answer ⏱ Complexity: Time: O(n) Space: O(1) ✔ Accepted ✔ Clean and efficient ✔ Bit manipulation reinforced Takeaway: Sometimes constraints quietly simplify the problem—spot them early. Practicing DSA daily with LeetCode, learning alongside CoderArmy, and guided by Rohit Negi. Consistency compounds. 🚀 #Day25/90 #LeetCode #DSA #BitManipulation #Math #ProblemSolving #CPlusPlus #LearningInPublic #ProblemSolving2026
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