When you miss a base case🧠 What is the best way to check it, what do you guys think??💬 When working with recursion, the most important step is often the simplest one: 💻Define your base case first. Before thinking about the recursive calls, pause and ask, like what’s the worst or simplest condition where the function should stop? Most of the time, that’s your base case. A small reminder from experience: 👉 Start with the base case 👉 Think about edge conditions first 👉 Then build the recursive flow Strong foundations make complex problems manageable. You can also check out✨, and learn CPP from the basics💻: https://lnkd.in/gdPC4D6f #Recursion #Programming #CPP #DSA #problemSolving #leetcode #basecase #lpu
Defining Base Case in Recursion: A Simple Yet Crucial Step
More Relevant Posts
-
🚀 Day 51 of #geekstreak60 Consistency is starting to feel powerful now 💪 Today’s Problem: Target Sum A classic dynamic programming problem that really tests your understanding of subset partitioning and optimization. 🔍 What I learned: How to convert a target sum problem into a subset sum problem Importance of edge case handling (like negative and odd cases) Optimization using 1D DP instead of 2D 💡 Key Insight: Instead of thinking in terms of '+' and '-', we can transform the problem into finding subsets with a specific sum this makes it much more efficient! ✅ Problem Solved 📸 Screenshot attached I'm 51 days in and not stopping anytime soon 🔥 #geekstreak60 #npci #geeksforgeeks #dsa #coding #programming #100DaysOfCode #developerjourney
To view or add a comment, sign in
-
-
64 of #100DaysOfCode 🚀 Solved LeetCode 46 – Permutations using the Recursion and in-place backtracking (swap) approach. 🔹 Instead of using extra space like visited[], I used swapping to generate permutations efficiently. 🔹 Fixed each index and tried all possible elements using recursion. 🔹 Backtracking (swap back) helped explore all possibilities without extra memory. 💡 Key Learning: Backtracking becomes more powerful when optimized with in-place operations — cleaner and faster! ⚙️ Time Complexity: O(n × n!) 📦 Space Complexity: O(n) (recursion stack) #leetcode #dsa #cpp #backtracking #codingjourney #programming #100daysofcode
To view or add a comment, sign in
-
-
42 of #100DaysOfCode Solved LeetCode 930 – Binary Subarrays With Sum 💡 Today’s problem was a great example of how powerful Prefix Sum + HashMap can be when dealing with subarrays. 🔹 Approach Used: Instead of checking all subarrays (which would be inefficient), I used a running prefix sum and stored its frequency in a hashmap. This reduces the time complexity to O(n) — much more efficient than brute force! ⚡ 🔹 What I Learned: Prefix sum helps convert subarray problems into lookup problems HashMap optimizes repeated computations Always think: “Can I store previous results to save time?” #LeetCode #DSA #CodingJourney #Programming #Cpp #SoftwareEngineering #ProblemSolving #LearnToCode
To view or add a comment, sign in
-
-
Last week, I was telling a friend about how great it would be to customize those Claude Code loading verbs that randomly appear after you prompt. Turns out I wasn’t the only one thinking this, since Anthropic actually made them configurable earlier this year. You can customize them entirely at a system, user, or project level via settings.json files (docs link in the comments). So naturally, I had to make a list of 100+ loading messages that would give any developer a mini heart attack when read. What would you customize yours to be? #claudecode #programming #softwaredeveloper
To view or add a comment, sign in
-
-
#Day58 Solved: Longest Substring Without Repeating Characters(Leetcode 3) Worked on one of the most asked string problems that really tests problem-solving and optimization skills. Problem: Find the length of the longest substring without repeating characters. Approach: Used the sliding window technique to efficiently track a valid substring. Instead of checking all possible substrings (which is slow), I dynamically adjusted the window: Expanded when characters were unique Shrunk when a duplicate appeared Key Learning: The biggest takeaway was understanding how to maintain a valid window rather than restarting every time a duplicate is found. Complexity: Optimized the solution from O(n²) to O(n) using the right approach. This problem strengthened my understanding of: Sliding Window Two Pointer Technique Optimizing brute force solutions #leetcode #dsa #programming #coding #slidingwindow #problemSolving
To view or add a comment, sign in
-
-
Solved LeetCode: Power of Two using Bit Manipulation Learned how to efficiently check whether a number is a power of 2 using binary properties. A number is a power of two if it has only one set bit in its binary representation. Used the trick: n > 0 && (n & (n - 1)) == 0 Optimized solution with: Time Complexity: O(1) Space Complexity: O(1) This problem helped me understand bit manipulation, binary concepts, and optimized checking techniques https://lnkd.in/dFdQhMmS GitHub Repo: https://lnkd.in/gg4daDpn #day10 #DSA #Cpp #LeetCode #Coding #Programming #Learning #ProblemSolving #BitManipulation
To view or add a comment, sign in
-
-
Solved LeetCode 151: Reverse Words in a String Today, I worked on reversing the order of words in a string while handling extra spaces efficiently. I learned how to: Remove leading, trailing, and multiple spaces Extract words correctly Reverse their order using clean logic and STL I implemented an optimized solution with: Time Complexity: O(n) Space Complexity: O(n) This problem helped me improve my understanding of string manipulation, edge case handling, and clean coding practices https://lnkd.in/getBKFiE GitHub Repo: https://lnkd.in/gg4daDpn #day18 #DSA #Cpp #LeetCode #Coding #Programming #Learning #ProblemSolving #Strings
To view or add a comment, sign in
-
-
Minimum Distance Between Three Equal Elements Thought process 🤔 Brute force: Run 3 loops, pick every (i, j, k), check if elements are equal, and calculate the absolute difference of indices. Keep updating the minimum. Simple approach, but yeah… O(n³) is too slow when input size grows 😅 How to optimize:: We only care about indices where values are the same, so instead of checking every triplet, let’s store them.. Use a map For each elem, store all its indices Then check only valid triplets from those indices, compute distances for valid groups and track the mini. O(n) time 💡 #leetcode #potd #programming #dsa #developer #softwareengineer #datastructures #algorithms
To view or add a comment, sign in
-
-
Solved the Target Sum Expression problem in C++ today. The challenge was to count how many different expressions can be formed by placing '+' or '-' before each number in an array so that the final result equals the target. For example: arr = [1, 1, 1, 1, 1], target = 3 Output = 5 What I learned: 1. Each number gives us two choices: add or subtract 2. This problem can be solved efficiently using Dynamic Programming 3. We track how many ways each sum can be formed as we move through the array Key takeaway: Instead of generating all expressions manually, DP helps us store intermediate results and avoid repeated work. #cpp #programming #dsa #dynamicprogramming #codingchallenge #leetcode #geekforgeeks #softwaredeveloper
To view or add a comment, sign in
-
-
Day 12 of 30 — async/await looks simple. These 3 mistakes prove it isn't 😬 Pitfall 1 → async void (exceptions disappear) Pitfall 2 → .Result / .Wait() (deadlock risk) Pitfall 3 → missing ConfigureAwait(false) in library code Before/after fixes for all 3 in the image 👇 Which of these have you run into? Be honest 👇 #CSharp #AsyncAwait #DotNet #Programming #SoftwareEngineering
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