LeetCode Problem || Find All Possible Stable Binary Arrays I(3129)🚀. Today I worked on the problem "Number of Stable Arrays". A stable array is an array consisting of 0s and 1s where we cannot place more than limit consecutive identical elements. 🔹 Key Idea To solve this, I used Recursion + Dynamic Programming (Memoization). The state of the problem depends on: Remaining zeros Remaining ones The last bit placed in the array The current streak (how many times the same bit has appeared consecutively) So the stored results in a 4D DP array Consistent practice on data structures and algorithms is helping me strengthen my problem-solving skills every day. #LeetCode #DynamicProgramming #Recursion #CodingPractice #DSA #Java
LeetCode 3129: Find Stable Binary Arrays with Recursion and DP
More Relevant Posts
-
“Most people try to overcomplicate this one… but the simplest approach wins.” Day 69 — LeetCode Progress Problem: Height Checker Required: Given an array of student heights, return the number of indices where the heights are not in the expected non-decreasing order. Idea: If we sort the array, we get the expected order. Now just compare the original array with the sorted version — mismatches are the answer. Approach: Create a copy of the original array Sort the copied array Traverse both arrays: Compare elements at each index If they differ → increment count Return the count Time Complexity: O(n log n) Space Complexity: O(n) #LeetCode #DSA #Java #Arrays #Sorting #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟴𝟭/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟳𝟴. 𝗦𝘂𝗯𝘀𝗲𝘁𝘀 | 𝗠𝗲𝗱𝗶𝘂𝗺 | 𝗝𝗮𝘃𝗮 Given an integer array, return all possible subsets (the power set) — no duplicates allowed. 𝗠𝘆 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗕𝗮𝗰𝗸𝘁𝗿𝗮𝗰𝗸𝗶𝗻𝗴: ✅ At each index, make a choice: include or exclude ✅ Recurse with the element added → then backtrack (remove it) ✅ Recurse again without the element ✅ Base case: when index == nums.length, save the current subset This explores every branch of the decision tree, giving us all 2ⁿ subsets cleanly. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: ⏱ Time: O(n × 2ⁿ) — 2ⁿ subsets, each copied in O(n) 📦 Space: O(n) recursion depth Backtracking is one of those patterns that feels magical once it clicks — the "add → recurse → remove" rhythm is the heart of so many classic problems. 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gZmezt_g 19 more days to go. Almost there! 💪 #LeetCode #Day81of100 #100DaysOfCode #Java #DSA #Backtracking #Recursion #CodingChallenge #Programming
To view or add a comment, sign in
-
Day 10 of LeetCode Today I tackled one of the classic dynamic programming challenges — Regular Expression Matching. The problem involves matching a string with a pattern that includes: matches any single character matches zero or more of the preceding element Approach: Built a 2D DP table where dp[i][j] represents whether substring s[0..i-1] matches p[0..j-1] Carefully handled * with two cases: Zero occurrence One or more occurrences Initialized edge cases for patterns like a*, a*b* Result: Accepted with optimal performance! This problem really strengthens understanding of: Pattern matching DP state transitions Edge case handling Consistency is key — one hard problem at a time #LeetCode #DataStructures #Algorithms #DynamicProgramming #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode Problem || Find All Possible Stable Binary Arrays II (3130)🚀 🔹 Problem Idea: We are given a number of 0s and 1s and a constraint called limit. The goal is to count the number of possible binary arrays such that no more than limit consecutive identical elements appear. 🔹 Approach: I used Dynamic Programming to track the number of valid arrays formed with: i zeros j ones and the last placed element (0 or 1). The DP state helps ensure that the consecutive limit condition is maintained while building the array. Always enjoying the process of learning and improving problem-solving skills! 💡 #LeetCode #DynamicProgramming #ProblemSolving #Java #CodingPractice #SoftwareEngineering
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
-
-
🚀 Day 61/100 – LeetCode Challenge ✅ Solved: 125. Valid Palindrome Today’s problem was all about string manipulation + two-pointer technique. 🔍 Approach: Ignored all non-alphanumeric characters Converted characters to lowercase Used two pointers (left & right) to compare characters If mismatch → not a palindrome 💡 Key Learning: Instead of creating a new string, using the two-pointer approach helps achieve O(1) space complexity, making the solution more efficient. ⚡ Performance: Runtime: 2 ms (Beats 99.35%) Memory: 44 MB 🔥 Small problem, but a great reminder that clean logic + optimization matters! #Day61 #LeetCode #100DaysOfCode #Java #CodingJourney #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
Day 51 of #100DaysOfLeetCode 💻✅ Solved #217. Contains Duplicate problem in Java. Approach: • Sorted the array using Arrays.sort() • Traversed the array starting from index 1 • Compared each element with its previous element • If any two adjacent elements are equal, returned true • If no duplicates are found, returned false Performance: ✓ Runtime: 24 ms (Beats 26.49% submissions) ✓ Memory: 76.56 MB (Beats 96.73% submissions) Key Learning: ✓ Practiced sorting-based approach for detecting duplicates ✓ Learned how sorting helps bring duplicate elements together ✓ Strengthened understanding of array traversal techniques 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
-
-
🚀100 Days of Code Day - 17 Problem Solved: Letter Combinations of a Phone Number Today I worked on an interesting backtracking problem where I generated all possible letter combinations from a given digit string (2–9), based on the classic phone keypad mapping. 🔍 Key Learnings: • Understood how recursion helps explore all possible combinations • Strengthened my knowledge of backtracking techniques • Improved problem-solving and logical thinking 💡Approach: Used a recursive backtracking method to build combinations step by step, exploring all possible letter mappings for each digit. 📌 Example: Input: "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] This problem is a great example of how powerful recursion can be when dealing with combinations. #Java #DSA #Backtracking #ProblemSolving #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 123/500 – LeetCode DSA Challenge Today I solved three problems covering strings and matrix manipulation. ✅ Valid Palindrome – Used two pointers while ignoring non-alphanumeric characters. TC: O(n) | SC: O(1) ✅ Determine Matrix Rotation – Rotated matrix up to 4 times and compared with target. TC: O(n²) | SC: O(n²) ✅ Reverse Submatrix – Reversed rows within a submatrix using two-pointer technique. TC: O(k²) | SC: O(1) 💡 Key Learning: Two-pointer approach works well in both strings and matrices, and matrix problems often involve rotation or transformation patterns. 👉 Day 122/500 #DSA #Java #500DaysChallenge #ProblemSolving #CodingJourney
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