Day 67 of #100DaysOfLeetCode 💻✅ Solved #91. Decode Ways problem in Java. Approach: • Checked if the input string is empty or starts with '0' • Initialized a DP array to store number of ways to decode up to each index • Used dp[i] = dp[i-1] if single digit is valid (1–9) • Added dp[i-2] if two-digit number is valid (10–26) • Returned dp[n] as the total number of decoding ways Performance: ✓ Runtime: 1 ms (Beats 99.90%) ✓ Memory: 41.5 MB (Beats 55%) Key Learning: ✓ Practiced dynamic programming with strings ✓ Strengthened understanding of single vs double digit constraints ✓ Reinforced how to build DP solutions incrementally Learning one problem every single day 🚀 #Java #LeetCode #DSA #DynamicProgramming #ProblemSolving #CodingJourney #100DaysOfCode
Java LeetCode #91 Decode Ways Solution
More Relevant Posts
-
Day 64 of #100DaysOfLeetCode 💻✅ Solved #724. Find Pivot Index problem in Java. Approach: • Calculated the total sum of the array • Maintained a variable left to track left sum • For each index, computed right sum as total - left - nums[i] • Compared left and right sums • If both are equal, returned the index as pivot • Updated left sum by adding current element Performance: ✓ Runtime: 1 ms (Beats 98.68% submissions) 🚀 ✓ Memory: 47.58 MB (Beats 32.00% submissions) Key Learning: ✓ Learned prefix sum technique for efficient calculations ✓ Practiced reducing time complexity from O(n²) to O(n) ✓ Strengthened understanding of array traversal and sum logic Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 82 of #100DaysOfLeetCode 💻✅ Solved #11. Container With Most Water problem in Java. Approach: • Used Two Pointer technique • Calculated area using min height and width • Moved pointer with smaller height inward • Tracked maximum area throughout Performance: ✓ Runtime: 5 ms (Beats 83.17% submissions) ✓ Memory: 77.35 MB (Beats 53.65% submissions) Key Learning: ✓ Mastered Two Pointer optimization technique ✓ Learned efficient area calculation strategy ✓ Improved decision-making for pointer movement Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 69 of #100DaysOfLeetCode 💻✅ Solved #349. Intersection of Two Arrays problem in Java. Approach: • Iterated through each element of the first array • Checked if the element exists in the second array • Used a temporary array to store intersection elements • Ensured no duplicates by checking already added elements • Copied the result into a final array of correct size Performance: ✓ Runtime: 4 ms (Beats 35.60%) ✓ Memory: 44.41 MB (Beats 96.71%) Key Learning: ✓ Practiced array traversal using nested loops ✓ Learned how to handle duplicates manually ✓ Improved understanding of set-like operations without using extra data structures Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Solved “Detect Cycles in 2D Grid” (LeetCode 1559) Worked on a classic graph problem and implemented an efficient DFS-based solution in Java. 🔍 Key idea: Treat the grid as an undirected graph and detect cycles by: Traversing only same-character neighbors Tracking the parent cell to avoid false cycles Identifying a cycle when visiting an already visited node (not parent) ⚡ Insight: Using a recursion stack (like in directed graphs) gives wrong results here — parent tracking is the correct approach. ⏱ Complexity: Time: O(m × n) Space: O(m × n) 📌 Also added a clean, documented version to my GitHub with test cases. 🔗 LeetCode: https://lnkd.in/d6CKa-BN 🔗 GitHub: https://lnkd.in/gnEfmGAg #Java #DSA #GraphAlgorithms #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 88 of #100DaysOfLeetCode 💻✅ Solved #56. Merge Intervals problem in Java. Approach: • Sorted intervals based on start time • Compared current interval with last merged interval • Merged overlapping intervals • Added non-overlapping intervals directly Performance: ✓ Runtime: 8 ms (Beats 91.28% submissions) 🚀 ✓ Memory: 49.16 MB (Beats 43.60% submissions) Key Learning: ✓ Learned interval merging technique ✓ Strengthened sorting + traversal logic ✓ Improved handling of overlapping ranges Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟵𝟴/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟳𝟬. 𝗖𝗹𝗶𝗺𝗯𝗶𝗻𝗴 𝗦𝘁𝗮𝗶𝗿𝘀 | 🟢 Easy | Java The gateway problem to Dynamic Programming — and one of the most iconic problems in DSA. 🪜 🔍 𝗧𝗵𝗲 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 You can climb 1 or 2 steps at a time. How many distinct ways can you reach the top of n stairs? 💡 𝗧𝗵𝗲 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 To reach step i, you either came from step i-1 (1 step) or step i-2 (2 steps). So ways(i) = ways(i-1) + ways(i-2) Sound familiar? It's literally the Fibonacci sequence. 🐇 ⚡ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗕𝗼𝘁𝘁𝗼𝗺-𝗨𝗽 𝗗𝗣 ✅ Base cases: dp[1] = 1, dp[2] = 2 ✅ Fill dp[i] = dp[i-1] + dp[i-2] for i from 3 to n ✅ Return dp[n] No recursion. No stack overflow. No repeated subproblems. Just a clean bottom-up table. 🧠 📊 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 ⏱ Time: O(n) — single pass 📦 Space: O(n) — can be further optimised to O(1) with just two variables This problem teaches the most important DP lesson: identify overlapping subproblems, store results, build up from the base. Every hard DP problem starts with this same thinking. 𝗔𝗻𝗱 𝘆𝗲𝘀 — 𝗷𝘂𝘀𝘁 𝗹𝗶𝗸𝗲 𝘁𝗵𝗲𝘀𝗲 𝘀𝘁𝗮𝗶𝗿𝘀, 𝘁𝗵𝗶𝘀 𝗰𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝘄𝗮𝘀 𝗰𝗹𝗶𝗺𝗯𝗲𝗱 𝗼𝗻𝗲 𝗱𝗮𝘆 𝗮𝘁 𝗮 𝘁𝗶𝗺𝗲. 🏔️ 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gS3DX_YW 𝗝𝘂𝘀𝘁 𝟮 𝗺𝗼𝗿𝗲 𝗱𝗮𝘆𝘀. 𝗧𝗵𝗲 𝘀𝘂𝗺𝗺𝗶𝘁 𝗮𝘄𝗮𝗶𝘁𝘀! 🏁 #LeetCode #Day98of100 #100DaysOfCode #Java #DSA #DynamicProgramming #Fibonacci #CodingChallenge #Programming
To view or add a comment, sign in
-
Day 72 of #100DaysOfLeetCode 💻✅ Solved #3866 “First Unique Even Element” problem in Java. Approach: • Traversed the array to find even numbers • For each even number, counted its occurrences in the array • If the count is exactly 1, returned that number • Continued until the first unique even number is found • Returned -1 if no such number exists Performance: ✓ Runtime: 1 ms (Beats 99.36% submissions) 🚀 ✓ Memory: 45.15 MB (Beats 98.39% submissions) Key Learning: ✓ Practiced combining conditions (even + uniqueness) ✓ Improved understanding of nested loop logic ✓ Learned how to filter and validate elements efficiently Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 68 of #100DaysOfLeetCode 💻✅ Solved #977. Squares of a Sorted Array problem in Java. Approach: • Traversed the array and squared each element • Used Arrays.sort() to sort the squared values • Returned the sorted array as the result Performance: ✓ Runtime: 10 ms (Beats 37.38% submissions) ✓ Memory: 47.98 MB (Beats 18.78% submissions) Key Learning: ✓ Practiced array transformation and sorting ✓ Learned how squaring affects order in sorted arrays ✓ Understood the importance of optimizing from O(n log n) to O(n) using two pointers Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 58/100 Today’s problem: Reverse Integer (LeetCode) 💡 What I learned: - How to reverse digits using modulo (%) and division (/) - Handling negative numbers automatically - Most important: dealing with 32-bit integer overflow without using long - Learned to check overflow before updating the result ⚡ Key Concept: Before doing "rev = rev * 10 + digit", always check: 👉 If value exceeds "Integer.MAX_VALUE" or "Integer.MIN_VALUE", return 0 🧠 Takeaway: Small problems can hide tricky edge cases. Overflow handling is the real challenge here! 💻 Language used: Java #Day58 #100DaysOfCode #Java #DSA #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
Solved LeetCode 17 – Letter Combinations of a Phone Number using backtracking in Java. Approach: Mapped each digit (2–9) to its corresponding characters using a simple array for O(1) access. Then used backtracking to build combinations digit by digit. For every digit: Pick each possible character Append → explore next digit → backtrack Key idea: Treat it like a tree of choices, where each level represents a digit and branches represent possible letters. Key learnings: Backtracking = build → explore → undo StringBuilder helps avoid unnecessary string creation Problems like this are about systematic exploration of choices Time Complexity: O(4^n * n) Space Complexity: O(n) recursion stack + output Consistent DSA practice is strengthening pattern recognition day by day. #Java #DSA #Backtracking #LeetCode #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
Explore related topics
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