🚀 Today’s #Learning: Solved the Climbing Stairs problem 🪜 using Dynamic Programming (Memoization) in #Java 📘 Problem: Given n stairs, you can climb either 1 or 2 steps at a time. How many distinct ways can you reach the top? ❌ Time Complexity: O(2ⁿ) ❌ Space Complexity: O(n) (due to recursion stack) 🧠 Approach 2 — DP with Memoization (Top-Down): Optimized by storing already computed results to avoid re-computation 👇 ✅ Time Complexity: O(n) ✅ Space Complexity: O(n) (DP array + recursion stack) 💡 Next Step: Convert it to a space-optimized bottom-up approach with O(1) space. 🧠 Approach 3 — Space Optimized (Bottom-Up DP) We only need the last two results at any time — just like Fibonacci. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) ⚙️ Super efficient — perfect for large inputs. 💬 Reflection: Loved how this problem builds intuition for Fibonacci-style DP and space optimization. Every step in #DSA makes problem-solving faster and more intuitive! #Java #DSA #DynamicProgramming #ProblemSolving #Algorithms #CodingPractice #SpaceOptimization #LearningEveryday #Striver #Preparation #Leetcode #Programming #Java #DSA #DynamicProgramming #ProblemSolving #Algorithms #CodingPractice #SpaceOptimization #LearningEveryday #Striver #Preparation #Leetcode #Programming
Solved Climbing Stairs problem using DP in Java
More Relevant Posts
-
💡 Day 104 of My DSA Challenge – Combinations 🔷 Problem : 77. Combinations 🔷 Goal : Generate all possible combinations of k numbers chosen from the range [1, n]. Example → Input: n = 4, k = 2 Output: [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]] 🔷 Key Insight : This is a backtracking problem — where we explore all possible ways of picking elements while maintaining order and avoiding repetition. The core difference from permutations is that the order of elements doesn’t matter — [1,2] and [2,1] are the same combination. 🔷 Approach : 1️⃣ Start from the first number (idx = 1). 2️⃣ At each step, decide whether to include the current number in the combination or skip it. 3️⃣ Recursively build combinations until the list size reaches k. 4️⃣ Backtrack to explore other possibilities. 🔷 My Java Approach : Used recursion to explore all inclusion/exclusion choices. Added combinations when list size equals k. Backtracked after each recursive call to maintain correct state. 🔷 Complexity : Time → O(C(n, k)) Space → O(k) (for recursion and temporary list) This problem strengthens understanding of decision trees and combinatorial logic, which form the backbone of many recursive and dynamic programming patterns. Every problem adds a new layer to logical thinking — today, it was about choosing without caring about order, but caring deeply about structure. #Day104 #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #Backtracking #Recursion #Combinations #CodingChallenge #Programming #SoftwareEngineering #Algorithms #DataStructures #TechJourney #EngineerMindset #DeveloperJourney #GrowthMindset #KeepLearning #ApnaCollege #AlphaBatch #ShraddhaKhapra
To view or add a comment, sign in
-
-
✨ Day 103 of My DSA Challenge – Permutations 🔷 Problem : 46. Permutations 🔷 Goal : Generate all possible orderings (permutations) of a given array of distinct integers. Example → Input: [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 🔷 Key Insight : This problem is a classic recursion and backtracking pattern — exploring all possible arrangements by making choices and undoing them. Here’s how I approached it : 1️⃣ Recursion (Depth-First Search): Build each permutation step by step. 2️⃣ Visited Array: Track which elements have been used so far. 3️⃣ Backtracking: After exploring a path, undo the choice (remove the last element and mark it unvisited). Every recursive call expands the decision tree until all positions are filled, ensuring every unique ordering is generated. 🔷 My Java Approach : Recursive helper() function generates all permutations. Base case → when current list size equals array length. Used a boolean[] vis to manage state efficiently 🔷 Complexity : Time → O(n × n!) (since there are n! permutations and copying each list takes O(n)) Space → O(n) (for recursion and visited tracking) This problem beautifully tests recursion fundamentals, state management, and the art of backtracking — essential tools for mastering combinatorial problems. Each problem reminds me that problem-solving is less about memorizing patterns and more about learning how to think. #Day103 #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #Recursion #Backtracking #CodingChallenge #Programming #SoftwareEngineering #Algorithms #DataStructures #TechJourney #CodeEveryday #EngineerMindset #DeveloperJourney #GrowthMindset #KeepLearning #ApnaCollege #AlphaBatch #ShraddhaKhapra
To view or add a comment, sign in
-
-
💡 Day 57 of #100DaysOfCode 💡 Today, I solved LeetCode Problem #217 – Contains Duplicate 🧩 Given an integer array, the task is simple yet fundamental: 👉 Determine whether any value appears at least twice in the array. 💻 Language: Java ⚡ Runtime: 13 ms — Beats 87.70% 🚀 📉 Memory: 58.28 MB — Beats 63.02% 🧠 Key Learnings: Reinforced my understanding of HashSet and its O(1) lookup time. Learned how sets help efficiently identify duplicates in large datasets. Strengthened array traversal and data structure optimization skills. 🧩 Approach: 1️⃣ Initialize an empty HashSet. 2️⃣ Iterate through each element in the array. 3️⃣ If an element already exists in the set → return true. 4️⃣ Else, add it to the set. 5️⃣ If loop completes, return false. ✅ Complexity: Time: O(n) Space: O(n) ✨ Takeaway: Even basic problems like these teach the power of hash-based structures — simple yet powerful for building optimized systems and preventing redundant computations. #100DaysOfCode #LeetCode #Java #DataStructures #HashSet #ProblemSolving #CodingChallenge #CleanCode #Programming #SoftwareEngineering #TechLearning #Algorithms
To view or add a comment, sign in
-
-
I’ve realized that DSA is not just about solving problems—it’s about how many you solve and how deeply you understand the underlying concepts. The more problems you practice, the easier it becomes to recognize patterns and apply the right approach. Today, I worked on LeetCode 1971 – Find if Path Exists in a Graph, marked as an Easy problem. But to solve it confidently, you actually need strong fundamentals in: 🔹 Graph theory 🔹 DFS & BFS (and when to use which) 🔹 Difference between Graphs vs Trees 🔹 Edge List vs Adjacency List 🔹 How to build an adjacency list in code 🔹 How DFS works internally on graphs After around two months of consistent practice, I’m finally able to identify the prerequisites required for each problem and approach them with a structured mindset. If you're exploring graphs, I highly recommend giving this problem a try. Here’s the problem: https://lnkd.in/g6hMyn88 And here’s my LeetCode profile if you'd like to connect or share feedback: https://lnkd.in/gp38YMN7 #LeetCode #DSA #Java #SoftwareEngineering #Graphs #Coding #LearningJourney
To view or add a comment, sign in
-
-
🔥 Day 17 of My LeetCode Journey — Problem #377: Combination Sum IV (Dynamic Programming) Today’s focus was on Dynamic Programming — specifically tackling problems where order matters in combinations. 🧩 Problem Summary: Given an array of distinct integers and a target integer, the task was to compute the number of possible combinations that sum up to the target. 💡 Approach & Key Insights: Utilized bottom-up Dynamic Programming (1D array approach) to efficiently compute results. Base case: dp[0] = 1, representing one way to reach a sum of zero. Iteratively built combinations where the sequence order impacts the outcome, differentiating it from subset problems. ⚙️ Algorithmic Complexity: Time: O(n × target) Space: O(target) 📈 Performance Outcome: ✅ Accepted Solution ⚡ Runtime: 1 ms (Beats 67.14% of Java submissions) 💾 Memory: 41.19 MB Each day’s challenge continues to refine my analytical reasoning and problem-solving efficiency, bringing me one step closer to mastering algorithmic design patterns in Java. #LeetCode #Java #DynamicProgramming #CodingJourney #ProblemSolving #TechLearning #SoftwareEngineering
To view or add a comment, sign in
-
-
🗓 Day 6 / 100 – #100DaysOfLeetCode 📌 Problem 2169: Count Operations to Obtain Zero The goal was to determine how many operations are needed to make both numbers zero by repeatedly subtracting the smaller one from the larger. 🧠 My Approach: Implemented the Euclidean Algorithm to optimize repeated subtraction. Instead of subtracting multiple times, used the modulus operator (%) to reduce steps efficiently. Counted the total number of operations until one of the numbers reached zero. ⏱ Time Complexity: O(log(min(a, b))) 💾 Space Complexity: O(1) 💡 Key Learning: This problem reinforced how mathematical insights like the Euclidean Algorithm can transform a brute-force approach into an elegant, optimized solution. It also reminded me of how language syntax (like Java’s integer operations) shapes the implementation of algorithmic logic. Each day brings a small improvement — and that’s what makes this journey meaningful 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Java #ProblemSolving #Algorithms #EuclideanAlgorithm #MathInCoding #DataStructures #DSA #CodingJourney #CompetitiveProgramming #SoftwareEngineering #CodeEveryday #LearningInPublic #DeveloperJourney #TechStudent #CodingCommunity #CareerGrowth #Programming #LogicBuilding #Optimization #KeepLearning
To view or add a comment, sign in
-
-
🔹 Day 40 – LeetCode Practice Problem: Find Greatest Common Divisor of Array (LeetCode #1979) 📌 Problem Statement: Given an integer array nums, find the greatest common divisor (GCD) of the smallest and largest numbers in the array. ✅ My Approach (Java): 1. Find the minimum and maximum elements in the array. 2. Starting from the smaller number and going downwards, check for the highest integer that divides both min and max. 3. Return that integer as the GCD. 📊 Complexity: Time Complexity: O(n + min(a, b)) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 43.41 MB (Beats 41.55%) 💡 Reflection: This problem shows how basic math logic and loop optimization can lead to extremely efficient solutions. A simple and powerful way to practice number theory in coding! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
I'm excited to share my next major project: a comprehensive "ONE SHOT" video series covering the first two units of Principles of Programming Languages (PPL). This series was a deep dive into what makes programming languages work. It required not just technical knowledge of C++ and Java, but also skills in: Comparative Analysis: Breaking down the differences in data types, memory management, and program structure between languages. Technical Communication: Explaining abstract concepts like programming paradigms, syntax vs. semantics, and binding. Project Management: Planning and producing a multi-video series from start to finish. The series covers all the core concepts of PPL Units 1 & 2: Unit 1: Fundamentals: Machine architecture, language design, and syntax vs. semantics. Unit 2: Structuring Data: Primitive, Derived (arrays, pointers), and User-Defined (structs, unions) Data Types. Unit 2: Program Structure: Control flow, expressions, subprograms, and paradigms (OOP, Functional, Procedural). I'm proud of this series and hope it helps other students. You can watch the full playlist here: https://lnkd.in/g-Un9SFJ #PrinciplesOfProgrammingLanguages #PPL #ComputerScience #Java #CPP #SoftwareDevelopment #ProjectManagement #TechnicalCommunication #EngineeringStudent
To view or add a comment, sign in
-
💻 Strengthening Problem-Solving Skills with LeetCode (Java) Recently explored a few interesting problems that focused on string manipulation, array traversal, and text formatting — each reinforcing clarity and precision in algorithmic thinking: 🔹 Text Justification Implemented a custom text alignment algorithm that evenly distributes spaces between words to fit a given line width. Approach: Greedy + StringBuilder Time Complexity: O(n) 🔹 Two Sum II – Input Array Is Sorted Solved using a two-pointer technique to efficiently find pairs that add up to a target value in a sorted array. Approach: Two Pointers Time Complexity: O(n) 🔹 Is Subsequence Checked whether one string is a subsequence of another using linear traversal and pointer comparison. Approach: Two Pointers Time Complexity: O(n) 🔹 Valid Palindrome Validated alphanumeric palindromes by filtering characters and comparing from both ends. Approach: String cleaning + two-pointer comparison Time Complexity: O(n) These problems helped sharpen my logic-building process and improved my confidence in designing efficient, readable solutions. #LeetCode #Java #ProblemSolving #DSA #Algorithms #Coding #SoftwareEngineering
To view or add a comment, sign in
-
𝐃𝐚𝐲 𝟏𝟖 𝐨𝐟 #50DaysOfDSA 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝟑𝟐𝟐𝟖 — 𝐌𝐚𝐱𝐢𝐦𝐮𝐦 𝐍𝐮𝐦𝐛𝐞𝐫 𝐨𝐟 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬 𝐭𝐨 𝐌𝐨𝐯𝐞 𝐎𝐧𝐞𝐬 𝐭𝐨 𝐭𝐡𝐞 𝐄𝐧𝐝 (𝐌𝐞𝐝𝐢𝐮𝐦) 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 - https://lnkd.in/gu-Rnxuv 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 - https://lnkd.in/gvh4gS2z Ever thought how many times you can shift all '1's to the end of a binary string? That’s exactly what this problem challenges you to find! 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐮𝐦𝐦𝐚𝐫𝐲: You’re given a binary string s. In one operation, you can pick an index i where s[i] == '1' and s[i+1] == '0', and move that '1' to the right until it reaches the end or just before another '1'. Your goal find the maximum number of such operations possible. 𝐈𝐧𝐭𝐮𝐢𝐭𝐢𝐨𝐧: Instead of simulating the moves, observe that: Each '1' can contribute operations only when it faces zeros that form a boundary (zero-block end). So, every time we hit the last zero of a block, we can add the count of '1's before it. This insight keeps the solution linear O(n) time, O(1) space! 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Sometimes, the key to optimizing problems isn’t simulation, it’s pattern recognition. Spot the structure → derive the formula → simplify! #LeetCode #Java #CodingChallenge #DSA #ProblemSolving #Programming #50DaysOfCode
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