Today, I implemented a program to find all permutations of a string using recursion, inspired by Aditya Verma’s approach. At first, it looked like just another coding problem... but when I visualized it, something clicked. 💡 Real-life analogy: Imagine you’re trying to arrange 3 books — A, B, and C — on a shelf. You pick one book (say A) and keep it on the first spot. Now you’re left with 2 books (B and C). You repeat the same step — pick one, place it, and continue. You’re basically fixing one and arranging the rest, which is exactly what recursion does here! Each recursive call is like asking a smaller version of yourself to finish the remaining arrangements 😄 Here’s what I learned: ✅ Recursion isn’t about memorizing steps — it’s about trusting smaller problems to solve the big one. ✅ Each function call gets its own copy of the string (call by value), making the logic clean and independent. ✅ Smart work was visualizing recursion as a decision tree 🌳; Hard work was debugging every swap, substring, and counter to ensure accuracy. #100DaysOfCode #DSA #Recursion #Cplusplus #CodingJourney #AdityaVerma #SoftwareEngineering #SmartWork #HardWork #Learning
"Implemented string permutation program using recursion, inspired by Aditya Verma"
More Relevant Posts
-
Solved LeetCode Problem #22: Generate Parentheses, a classic example of using backtracking and recursion to generate valid combinations. The problem reinforced how powerful state tracking can be — deciding when to add an opening or closing parenthesis based on previous choices ensures every combination remains valid. What I really enjoyed about this problem is how it visually represents the beauty of recursion — every path explores a new possibility, but only valid paths make it to the final answer. 🔍 Key Takeaways: Backtracking is not about brute force, but smart exploration. Maintaining the right balance between open and close parentheses is the core idea. Visualizing recursion as a decision tree really helps in understanding the flow. It’s one of those problems that looks simple on the surface but beautifully demonstrates how clean logic can solve complex combinations. #LeetCode #Cplusplus #Backtracking #Recursion #ProblemSolving #DSA #CodingJourney #LogicBuilding
To view or add a comment, sign in
-
-
🚀 Day 52 of LeetCode 150 Days Challenge — Valid Parentheses #Day52 #LeetCode150 #CodingChallenge #DSA #Stack #Cplusplus #LeetCode #150DaysOfCode #CodeEveryday #LearnToCode #ProblemSolving #SoftwareEngineering #SDEPreparation #InterviewPrep 🧩 Problem Statement Given a string s containing only the characters '(', ')', '{', '}', '[', and ']', determine if the input string is valid. 👉 A string is valid if: Open brackets are closed by the same type of brackets. Brackets are closed in the correct order. ⚙️ Intuition This problem is about balancing parentheses — every opening bracket must have a matching closing one in order. A stack is perfect here since it follows LIFO (Last-In-First-Out) order: Push opening brackets onto the stack. When a closing bracket appears, check if it matches the top of the stack. If it matches → pop it. If not → invalid. At the end, if the stack is empty → it’s valid. 🧠 Example Dry Run Input: s = "{[()]}" Process: { → push [ → push ( → push ) → matches ( → pop ] → matches [ → pop } → matches { → pop Stack is empty → ✅ Valid ⏱ Complexity Analysis Time: O(n) — one pass through string Space: O(n) — for the stack 🌱 Takeaway This problem reinforces: Stack fundamentals Parentheses matching logic Edge case handling (unbalanced or extra closing brackets)
To view or add a comment, sign in
-
-
🚀 Day 66 of #100DaysOfCode Today’s problem was LeetCode 155 — Min Stack 🧠💪 📌 Problem Summary: We need to design a stack that supports: push() pop() top() getMin() (returns minimum element in O(1) time) All operations must be O(1) — that’s the tricky part. ⚡ 📌 Approach: 👉 Use a single stack to store modified values 👉 Track the minimum separately using a variable 👉 When pushing a smaller value, encode it cleverly so you can retrieve the previous min during pop() 💡 Key Insight: When inserting a value smaller than the current minimum: st.push(2*x - min) min = x This way, the stack encodes both data and min info efficiently. 📌 Complexity: ⏱ Time: O(1) for all operations 💾 Space: O(n) ✨ Learning: This is a great example of space optimization and bit manipulation logic — classic low-level trick that feels like magic the first time you see it! ⚙️ Raj Vikramaditya Raghav Garg Nancy Solanki Shweta Arora Harsh Raj Harshita Verma Love Babbar Prince Singh Shivam Mahajan Rohit Negi Neeraj Walia Nishant Chahar Kushal Vijay #LeetCode #100DaysOfCode #CodingChallenge #Cplusplus #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering #Developers #Programming #TechJourney #KeepLearning #DailyCoding #CodeNewbie#LeetCode #100DaysOfCode #Programming #Cplusplus #LinkedList #ProblemSolving #SoftwareEngineering #TechJourney #CodeNewbie #DSA
To view or add a comment, sign in
-
-
🚀 How I Solved LeetCode’s Word Search Problem Without DFS or Recursion When I came across Word Search (LeetCode 79), I noticed that almost every solution used DFS and backtracking. But I wanted to solve it my own way — using index tracking and adjacency logic instead of recursion. My intuition was simple: If a word exists in the grid, every next letter must lie right next to the previous one — either up, down, left, or right. That means their coordinate difference should satisfy: abs(x1 - x2) + abs(y1 - y2) == 1. This small observation became the foundation of my entire approach. 💡 My Thought Process 1️⃣ I mapped every letter in the grid to its coordinates. 2️⃣ I started from all positions of the first letter in the word. 3️⃣ For every next letter, I checked which positions are adjacent and not already used. 4️⃣ I extended paths step by step — no recursion, only iteration. 5️⃣ If any path reached the last letter → the word exists. ⚙️ My Implementation I used a BFS-style iterative search, where each state holds: the current cell (x, y) the current index in the word and a bitmask representing already-used cells. This replaced recursion and heavy visited[][][] arrays with a compact integer mask. Each move just extended to adjacent cells if the next character matched. It handled tricky cases like "ABCB" perfectly → returned false, which even some DFS implementations fail on. ✅ Why It Worked ✔️ No recursion = no stack overflow. ✔️ Bitmask = minimal memory use. ✔️ Adjacency rule = exactly matches grid movement. ✔️ Iterative BFS = simple, efficient, and logical. 🎯 What I Learned You don’t always need to follow the standard algorithms. Sometimes, just trusting your intuition and building around your idea leads to something even better. This problem taught me that creativity and logic go hand in hand. And when you believe in your approach — it truly works. 💪 #Coding #LeetCode #ProblemSolving #Cplusplus #Innovation #DSA #Learning #DeveloperJourney
To view or add a comment, sign in
-
-
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
-
-
Data Structures & Algorithms: Merging Two Sorted Linked Lists For my lab assignment, I tackled the LeetCode problem “Merge Two Sorted Lists” using C++ linked lists and pointer manipulation. 🔹 My Approach: I compared the first nodes of both lists, chose the smaller one as the head, and then iteratively attached the next smallest nodes using a pointer (curr). Once one list was exhausted, I simply linked the remaining nodes from the other list to finish the merge efficiently. 🔹 Key Concepts Covered: • Linked Lists • Pointer updates • Iterative merging ⏱ Time Complexity: O(n + m) This assignment really strengthened my understanding of linked list traversal and handling edge cases effectively. 🎥 Check out my video explanation: https://lnkd.in/dgZRyjj2 💡 Fun fact: I realized that merging linked lists is much easier in code than in real life—thankfully! #DSA #LabAssignment #LeetCode #C++ #CodingPractice #ProblemSolving #MergeTwoSortedLists
Merge two sorted lists - TUTORIAL LEETCODE
https://www.youtube.com/
To view or add a comment, sign in
-
🚀 Day 45 of LeetCode 150 Days Challenge #LeetCode #Day45 #HappyNumber #DSA #Hashing #Cplusplus #CodingChallenge #SDE #ProgrammingJourney 💡 Problem: Happy Number 🔗 Topic: Hashing / Math 🧩 Problem Statement: A Happy Number is defined as follows: Start with any positive integer n, Replace the number by the sum of the squares of its digits. Repeat the process until the number becomes 1 (✅ happy number), or it loops endlessly in a cycle that does not include 1 (❌ not happy). Return true if n is a happy number, else false. 🔍 Example: Input: n = 19 Steps: 1² + 9² = 82 8² + 2² = 68 6² + 8² = 100 1² + 0² + 0² = 1 ✅ Since we reached 1, 19 is a happy number 🎉 ⚡ Approach: Using Hash Set to Detect Loops 👉 We repeatedly calculate the sum of squares of digits. 👉 To detect infinite loops, we use a hash set to store previously seen numbers. If a number repeats → cycle detected → return false. If it becomes 1 → return true. ⏱ Complexity: Time: O(log n) (digits squared repeatedly) Space: O(log n) (to store seen numbers) ✅ Takeaway: This problem beautifully combines math and hashing — using sets to break cycles and identify when a process loops infinitely. 💡
To view or add a comment, sign in
-
-
🔢 Day 17 of my 120 Days LeetCode Challenge 🚀 Problem: Letter Combinations of a Phone Number (LeetCode #17) Difficulty: Medium 💡 Problem Statement Given a string containing digits from 2–9, return all possible letter combinations that these numbers could represent — similar to how numbers map to letters on a phone keypad. Each digit maps to specific letters as shown below: 2 → abc 3 → def 4 → ghi 5 → jkl 6 → mno 7 → pqrs 8 → tuv 9 → wxyz For example: Input: "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] ⚙️ Algorithm Used: Backtracking (DFS Approach) I solved this problem using backtracking, a depth-first search technique that explores all possible combinations by building them step by step and undoing choices when necessary. How it works: Start from the first digit and retrieve its possible letters. Recursively append each letter to the current combination. When a complete combination (equal in length to the input digits) is formed, add it to the result list. Backtrack by removing the last letter and trying the next one. This ensures that all possible combinations are explored systematically. ⏱ Time Complexity: O(3ⁿ × 4ᵐ) n → number of digits mapping to 3 letters (2, 3, 4, 5, 6, 8) m → number of digits mapping to 4 letters (7, 9) 💾 Space Complexity: O(N) — due to recursion and temporary string storage during backtracking. 🧩 Key Takeaways: Learned how to apply recursive backtracking effectively. Improved understanding of combinatorial problems and string manipulation in C++. Strengthened logical thinking through recursive tree exploration. #LeetCode #CodingChallenge #Day17 #Cplusplus #DSA #Backtracking #ProblemSolving #100DaysOfCode #SoftwareEngineering #TechJourney
To view or add a comment, sign in
-
-
Day 13 of #100DaysOfCode Today, I explored one of the most powerful tools in C++ — the Standard Template Library (STL). 💡 STL is like a treasure chest for developers — it provides ready-to-use data structures and algorithms that make coding more efficient and elegant. Here’s what I learned today: ✅ Containers like vector, list, set, and map — to store and manage data effectively. ✅ Iterators — to traverse elements just like pointers. ✅ Algorithms — for operations such as sorting, searching, and reversing with just one line of code. ✅ How STL helps in writing cleaner, faster, and more reusable code. Understanding STL feels like unlocking superpowers in C++ — it truly saves time and effort in solving complex problems! 💪 #100DaysOfCode #CPlusPlus #STL #LearningEveryday #CodingJourney #ProblemSolving #DevelopersJourney
To view or add a comment, sign in
-
Day 6 – LeetCode Challenge Today, I solved Problem #128: “Longest Consecutive Sequence” using C++. 🔍 Problem Overview: The task is to find the length of the longest consecutive elements sequence in an unsorted integer array. The key challenge is to ensure the solution works in O(n) time complexity. 💡 Approach: To achieve linear time, I used an unordered_set to quickly check if a number exists. For each number, I only begin counting a sequence when it is the start of a new streak (i.e., (num - 1) does not exist in the set). This ensures each number is processed only once. 🧠 Algorithm Design: Insert all elements into an unordered_set for O(1) average lookups. For every number, check if it's the start of a sequence. If yes, count forward (num + 1, num + 2, ... ) while elements exist in the set. Track and update the maximum streak length. ⏱ Time Complexity: O(n) 📌 Space Complexity: O(n) #LeetCode #CPlusPlus #DSA #100DaysOfCode #ProblemSolving #Algorithms #CodingChallenge #TechCommunity #GeetaUniversity
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