Today I tackled the "Total Step Count" problem. While the logic seems simple—you can take 1 step or 2 steps at a time—implementing it through recursion really tests your understanding of base cases and the call stack. I've shared two snippets in my screenshot: The first tracks paths using a global variable. The second uses a more concise recursive return. It’s not just about getting the right answer; it’s about understanding the flow of the data. Every bug fixed is a lesson learned! #LearningToCode #PythonProgramming #DSA #ProgrammingLife #StudentDeveloper
Solving Total Step Count Problem with Recursive Logic
More Relevant Posts
-
🚀 Day 32 | 100 Days of Coding Challenge #DrGViswanathanChallenge 📘 Problem Solved: Implement Queue using Stacks (LeetCode) 🔧 Approach Used (Stack Reversal Technique): • Used two stacks to simulate queue behavior (FIFO) • While pushing, moved all elements from st1 → st2, inserted new element, then moved back • Ensured the oldest element stays on top for correct dequeue order 📌 Key Idea: Reverse the stack during push so that the front of the queue is always accessible at the top. ⏳ Complexity: Push: O(n) Pop: O(1) Peek: O(1) Space: O(n) 🧠 Key Learning: Reversing order using stacks helps simulate queue operations effectively—understanding internal behavior of data structures is key. 📂 Topics Covered: Stack, Queue, Data Structures, Simulation #100DaysOfCode #DSA #CPP #LeetCode #CodingJourney #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 88 / 100 – 100 Days of LeetCode Challenge 🚀 Problem: Strictly Palindromic Number (LeetCode #2396) Today I solved the Strictly Palindromic Number problem. The task is to determine whether a given integer n is strictly palindromic in all bases from 2 to n−2. Approach Instead of converting the number into every base and checking manually, I analyzed the mathematical property of the problem. It turns out that for any integer n ≥ 4, the number cannot be strictly palindromic in all required bases. Therefore, the result will always be false. Steps followed: • Understand the definition of strictly palindromic numbers • Analyze the mathematical behavior of numbers in different bases • Apply the observation that such numbers do not exist for n ≥ 4 • Directly return false This approach avoids unnecessary computation and relies on mathematical reasoning. Complexity Time Complexity: O(1) Space Complexity: O(1) Result ✔ Accepted ⚡ Constant time solution 🧠 Mathematical insight-based optimization A good problem to strengthen understanding of mathematical reasoning and problem analysis. #100DaysOfCode #100DaysLeetCodeChallenge #LeetCode #DSA #CPlusPlus #ProblemSolving #Math #Logic
To view or add a comment, sign in
-
-
Day 32/75 🚀 Solved Maximum Depth of Binary Tree (LeetCode 104) today! ✅ All 39/39 test cases passed ⚡ Runtime: 0 ms (Beats 100%) 💾 Memory: 18.94 MB (Beats ~77%) 🔍 Approach: Used recursion (DFS) to calculate depth of the tree. ✔️ If node is NULL → return 0 ✔️ Recursively find depth of left subtree ✔️ Recursively find depth of right subtree ✔️ Return 1 + max(leftDepth, rightDepth) This naturally explores the tree depth-first. 💡 Key Learning: Tree problems often become intuitive with recursion. Think in terms of subproblems (left + right) and combine results. Consistency + recursion thinking = strong tree concepts 🌳 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
Day 59/100 — Smallest Missing Multiple of K ✅ Today’s problem focused on finding the smallest positive multiple of a number that is missing from an array. Approach: Store all numbers from the array in a hash set for fast lookup. Start checking multiples of k (k, 2k, 3k, ...). Return the first multiple that is not present in the set. Key Learning: Using a hash set makes membership checking very efficient (O(1)). Problems involving repeated lookups often become much simpler with the right data structure. Problem Solved: Smallest Missing Multiple of K Language Used: C++ Status: Accepted ✔️ #100DaysOfCode #DSA #Arrays #HashSet #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Solved “Mirror Distance of an Integer” – A Simple Yet Insightful Problem -- Today I worked on a problem that looks simple at first glance but highlights the importance of number manipulation and logic building. -- Problem Statement: Given an integer n, find the mirror distance, defined as the absolute difference between the number and its reversed form. -- Approach: - Reverse the integer using digit extraction (n % 10), Build the reversed number step by step, Compute the absolute difference. -- Key Learnings: - How to reverse integers efficiently - Importance of digit manipulation - Writing clean helper functions (getReverse) - Keeping logic modular and readable #DSA #ProblemSolving #CPlusPlus #CodingJourney #LeetCode #SoftwareEngineering #Algorithm
To view or add a comment, sign in
-
-
#DAY03 #NXTWAVECCBP #PYTHONPROGRAMMING 🔄 Recap: Change Data Type (Type Conversion) Understanding data types is fundamental in programming—and knowing how to convert between them is just as important. 👉 Type Conversion is the process of converting a value from one data type to another. For example: • String ↔ Integer • Integer ↔ Float 💡 Why it matters? Because real-world data doesn’t always come in the format you need. Converting data types helps ensure accuracy, prevents errors, and makes your code more flexible. 📌 Quick takeaway: Clean data + correct type = reliable results. #Programming #DataTypes #TypeConversion #CodingBasics #LearnToCode #TechSkills
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Today I solved "Path Sum III" on LeetCode using a DFS + Recursion approach. Key Idea: We need to count all paths where the sum of node values equals the target. The path doesn’t have to start from the root — it can start from any node! Approach: • For every node, treat it as a starting point • Use DFS to explore all downward paths • Reduce the target at each step (target - node->val) • If a node matches the remaining target → count it • Repeat the process for left and right subtrees Why this works: Every node gets a chance to act as the starting point, and DFS ensures we explore all possible paths efficiently. Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Backtracking (implicit) Time Complexity: O(n²) in worst case Space Complexity: O(h) This problem helped me understand how to explore all possible paths in a tree, not just root-based ones — a big step forward in mastering tree problems From single path problems → to handling multiple dynamic paths… growing every day #Day90 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Daily | Day 72 🔥 LeetCode POTD – 3653. XOR After Range Multiplication Queries I (Medium) ✨ 📌 Problem Insight Given an array and queries: ✔ Each query updates indices in a range [l, r] ✔ Jump pattern using step k (i.e., l, l+k, l+2k...) ✔ Multiply elements by v under modulo ✔ Finally compute XOR of entire array 🔍 Initial Thinking – Direct Simulation ✅ 💡 Idea: ✔ For each query, iterate from l → r with step k ✔ Apply multiplication ✔ After all queries, compute XOR ⏱ Works because: ✔ Constraints are small (n, q ≤ 1000) ✔ Even worst case passes comfortably ⚠️ Common Pitfall ❌ 💡 Mistake: ✔ Misreading query format [l, r, k, v] ✔ Using wrong index for v 💡 Important Fix: ✔ Always use v = query[3] ✔ Use 1LL * a * b to avoid overflow 💡 Key Observation 🔥 ✔ This looks complex due to jumps (k) ✔ But no overlapping pattern optimization needed ✔ Pure simulation + careful coding is enough ⏱ Complexity: ✔ Time: O(q * n) ✔ Space: O(1) 🧠 Key Learning ✔ Not every problem needs optimization ✔ Read queries carefully (indexing matters!) ✔ Handle overflow using long long ✔ Simulation problems test implementation skills 🚀 Takeaway A clean simulation problem where correctness > complexity — perfect for building attention to detail ⚡ #LeetCode #DSA #Algorithms #CPlusPlus #ProblemSolving #CodingJourney #DataStructures
To view or add a comment, sign in
-
-
Day 4 of #100DaysOfCode Solved: Rotate Function (LeetCode 396) Approach 1: Brute Force Rotate array each time → O(n) Recalculate F(k) → O(n) Total: O(n²) (Too slow) Approach 2: Optimized (Using Relation) Instead of recomputing, reuse the previous value: Each rotation shifts elements by +1 index Last element moves to index 0 Use relation to compute next value in O(1) Total: O(n) Key Intuition: When array rotates: Every element’s contribution increases by its value But we subtract n × last element to adjust Takeaway: Whenever a problem involves repeated recomputation after shifts/rotations look for a mathematical relation #LeetCode #DSA #CodingInterview #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 12/30 – Dijkstra on Grid and Minimum Effort Path Day 12 of the challenge was focused on solving a more advanced graph problem and understanding how shortest path algorithms work beyond simple BFS. Today’s problem pushed me to think differently about “distance” and how it can be defined in different ways. DSA – Path With Minimum Effort Today I solved Path With Minimum Effort, a problem based on a variation of Dijkstra’s Algorithm. Problem Understanding • Given a grid of heights • Move in 4 directions (up, down, left, right) • Effort of a path = maximum absolute difference between consecutive cells • Goal is to minimize this maximum effort Approach Used – Dijkstra (Min Heap) Why not BFS: • Edges do not have equal weight • Each move has different cost (height difference) Steps: • Use a priority queue (min heap) • Store (effort, row, col) • Initialize effort at start as 0 • For each move, calculate new effort as: max(current effort, abs(height difference)) • Update if new effort is smaller • Continue until reaching bottom-right cell Key Insight • This is not about minimizing sum, but minimizing the maximum edge cost • Dijkstra can be modified to handle different definitions of distance • Priority queue ensures we always explore the least effort path first Time Complexity • O(n × m × log(n × m)) Space Complexity • O(n × m) Takeaways • Not all shortest path problems are about sum of weights • Understanding problem constraints changes the algorithm choice • Dijkstra is very flexible when adapted correctly • Grid problems continue to build strong graph intuition Day 12 completed. Problems are getting tougher, but so is the understanding. #30DaysChallenge #Day12 #DSA #DataStructures #Algorithms #Graphs #GraphTheory #Dijkstra #ShortestPath #GridProblems #Java #CodingJourney #ProblemSolving #InterviewPreparation #LeetCode #CompetitiveProgramming #TechLearning #Consistency #LearningInPublic #GrowthMindset
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