🚀 #100DaysOfCode – Day 10 | DSA Practice Continuing my 100 Days Data Structures and Algorithms challenge, today I worked on a problem based on bit manipulation and dynamic programming. 📌 Problem: Counting Bits Given an integer n, return an array ans where each index i (0 ≤ i ≤ n) contains the number of 1’s in the binary representation of i. Example: Input: n = 5 Output → [0,1,1,2,1,2] 🧠 Approach / Logic: 1️⃣ Initialize a result array of size n + 1. 2️⃣ Start from i = 1 and go till n. 3️⃣ For each number i, divide it by 2 → i / 2 (this removes the last bit). 4️⃣ Check if the last bit is 1 using i % 2. 5️⃣ Use the relation: ans[i] = ans[i / 2] + (i % 2) 6️⃣ This helps reuse previously computed results → making it efficient. 📊 Time Complexity: O(n) 📦 Space Complexity: O(n) 🎯 Key Learning: This problem shows how bit manipulation + dynamic programming can optimize solutions from brute force to linear time. Consistency is the key to growth. Let’s keep improving step by step! 💪 #100DaysOfCode #DSA #CodingJourney #ProblemSolving #CPP #LearningInPublic
100 Days of Code: Bit Manipulation and Dynamic Programming Challenge
More Relevant Posts
-
Day 16/50 – DSA Challenge Today was about designing something smarter, not just solving. ->Min Stack This problem looks simple… until you realize: “getMin() must be O(1)” That’s where the real thinking starts. What I learned today: • Using an extra stack to track minimums is a design decision, not just coding • Every push/pop must maintain consistency between two stacks • This problem is less about loops and more about data structure design Key Insight: Good programmers solve problems. Better programmers design systems that make problems easier. ⚙️ From brute force → optimized → now smart data structure design That’s real progress. #DSA #LeetCode #DataStructures #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
🚀 3-Month DSA Challenge | Week 2 Continuing my journey to consistently practice Data Structures & Algorithms and share my learning every week. 📚 Week 2 Topic: Arrays An array is one of the most basic and important data structures in programming. 👉 It stores multiple elements of the same type in a contiguous memory location. 👉 Each element can be accessed using an index (starting from 0). 💡 Why Arrays are important? ✔️ Fast access using index → O(1) ✔️ Helps in solving problems like searching, sorting, and subarrays ✔️ Base for advanced data structures like stacks, queues, and matrices 📌 Example: Array: [10, 20, 30, 40] Index: 0 1 2 3 👉 arr[2] = 30 🔥 Key Operations: • Traversal • Insertion • Deletion • Searching • Sorting 💭 My Learning: Arrays look simple, but mastering them helps in solving complex problems like: • Maximum subarray sum • Two pointer problems • Sliding window techniques Looking forward to strengthening my problem-solving skills through consistent DSA practice. 🚀 #DataStructures #DSA #Java #Learning #CodingJourney #InterviewPreparation
To view or add a comment, sign in
-
-
Solved: Find Pivot Index (LeetCode 724) Today I worked on a classic Prefix Sum problem that strengthens the foundation for many array-based questions. Problem Summary: Find an index in the array such that the sum of elements on the left is equal to the sum of elements on the right. Key Learning: Instead of recalculating sums repeatedly, we can optimize the approach using a total sum and a running left sum. Core Idea: Compute total sum of the array Traverse the array while maintaining left_sum Derive right_sum using: total_sum - left_sum - current_element Compare left_sum and right_sum at each index This reduces the time complexity from O(n²) to O(n), which is optimal. What I Practiced: Prefix Sum technique Optimization from brute force to efficient solution Writing clean and readable C++ code Consistency is key in DSA. Small problems like this build strong problem-solving intuition for bigger challenges. #DSA #LeetCode #ProblemSolving #Cpp #CodingJourney #PrefixSum
To view or add a comment, sign in
-
-
Day 3 – 7 Days of DSA Challenge Today’s problem is based on Binary Search Trees (BST) and counting how many unique structures we can form. Problem Statement We are given 4 distinct values: 1, 2, 3, 4. We need to find how many unique Binary Search Trees (BSTs) can be formed using all these values. Conditions: Each value must be used exactly once BST property must be maintained: Left subtree < Root Right subtree > Root My Thought Process At first, trying to draw all possible BSTs feels possible, but it quickly becomes complex. Then I realized this follows a pattern. Key Insight For any number n, we try choosing each value as the root. If we pick a root i: Left subtree will have (i - 1) nodes Right subtree will have (n - i) nodes Total trees formed with root i: left_subtrees * right_subtrees Recurrence Relation Let dp[n] = number of unique BSTs with n nodes dp[n] = Σ (dp[i-1] * dp[n-i]) for i = 1 to n Step-by-Step for n = 4 dp[0] = 1 dp[1] = 1 dp[2] = 2 dp[3] = 5 dp[4] = 1*5 + 1*2 + 2*1 + 5*1 = 14 Final Answer Number of unique BSTs with 4 nodes = 14 Code (Dynamic Programming) class Solution { public: int numTrees(int n) { vector<int> dp(n + 1, 0); dp[0] = 1; dp[1] = 1; for(int nodes = 2; nodes <= n; nodes++) { for(int root = 1; root <= nodes; root++) { dp[nodes] += dp[root - 1] * dp[nodes - root]; } } return dp[n]; } }; What I Learned Today BST counting problems follow a clear recursive pattern This is a classic Catalan Number problem Dynamic programming helps avoid recomputation #dsa #dsastreakwithpwskills #pwskills #datastructure
To view or add a comment, sign in
-
🚀 #100DaysOfCode – Day 15 | DSA Practice Continuing my 100 Days Data Structures and Algorithms challenge, today I solved an interesting problem based on numbers and digit manipulation. 📌 Problem: Check if The Number is Fascinating Given a 3-digit number n, we need to check whether it is fascinating or not. A number is called fascinating if: 👉 Concatenate n, 2*n, and 3*n 👉 The resulting number contains all digits from 1 to 9 exactly once 👉 It should not contain 0 Example: Input: n = 192 Concatenation → 192384576 Output → true 🧠 Approach / Logic: 1️⃣ Convert the numbers n, 2*n, and 3*n into strings and concatenate them. 2️⃣ Check if the total length of the string is 9. 3️⃣ Traverse the string and count the frequency of each digit. 4️⃣ If any digit is 0, return false. 5️⃣ Ensure each digit from 1 to 9 appears exactly once. 6️⃣ If all conditions are satisfied, the number is fascinating. 📊 Time Complexity: O(1) 📦 Space Complexity: O(1) 🎯 Key Learning: This problem highlights how string manipulation and frequency counting can be used to validate patterns in numbers. Consistency is the key to growth. Let’s keep improving every day! 💪 #100DaysOfCode #DSA #CodingJourney #ProblemSolving #CPP #LearningInPublic
To view or add a comment, sign in
-
-
**🪝 Hook:** Unraveling Complexity: The Power of Understanding Over Coding 🧠 **📖 Story/Context:** Today marks Day 23 of my Data Structures and Algorithms (DSA) journey. I delved into the intricacies of Depth First Search (DFS). At first glance, the algorithm seemed daunting, with its complex logic and potential pitfalls. **💡 Insight/Value:** Surprisingly, the code to implement DFS was just 3-4 lines long. This revelation highlighted a crucial insight: mastering the underlying concepts is far more valuable than memorising code snippets. Understanding DFS empowers you to tackle various problems, while mere coding knowledge limits your flexibility. **🎯 CTA:** How do you balance understanding concepts with practical coding skills? Share your thoughts or experiences in the comments below! 👇 #DSAJourney #DepthFirstSearch #ConceptOverCode #LearningEveryDay #TechCommunity
To view or add a comment, sign in
-
-
Day 152/365 – DSA Challenge 🚀 Solved Minimum Path Sum on LeetCode today. 🔹 Problem: Given a grid filled with non-negative numbers, find a path from the top-left to bottom-right that minimizes the sum of all numbers along its path. You can only move right or down. 🔹 Approach Used: Dynamic Programming (DP) Steps followed: 1️⃣ Create a DP table where dp[i][j] represents the minimum path sum to reach cell (i, j). 2️⃣ Initialize the starting cell: dp[0][0] = grid[0][0] 3️⃣ For each cell, compute: [ dp[i][j] = grid[i][j] + min(dp[i-1][j], dp[i][j-1]) ] 4️⃣ Fill the table row by row until reaching the bottom-right corner. 🔹 Key Idea: Each cell depends only on the minimum of top and left paths, making it a classic DP problem. 🔹 Time Complexity: O(m × n) 🔹 Space Complexity: O(m × n) (can be optimized to O(n)) 💻 Language: C++ This problem is a fundamental example of grid-based dynamic programming, often asked in interviews. #Day152 #365DaysOfCode #DSA #LeetCode #DynamicProgramming #GridProblems #CodingChallenge #Cpp
To view or add a comment, sign in
-
-
🚀 DSA Deep Dive – Day 38 Solved Distinct Subsequences today. And I realized… Dynamic Programming is not just about finding answers. Sometimes it’s about counting possibilities under constraints. 🤯 The problem looks simple: Given two strings s and t, find how many subsequences of s equal t. Not substring. Subsequence. That means skipping is allowed… and that’s where complexity begins. 👀 Here’s what I learned 👇 • Define dp[j] = number of ways to form t[0…j-1] • Base case: dp[0] = 1 ✅ (empty string always possible) • Traverse s and update dp backwards At every character, you decide: 👉 Take this character (if it matches) 👉 Or skip it ⚙️ Transition If s[i-1] == t[j-1]: 👉 dp[j] += dp[j-1] Each match adds new ways. Brute force recursion: Exponential 💀 Optimized DP: O(n × m) ⚡ Space optimized: O(m) 🚀 💡 The Powerful Shift Instead of asking “How many subsequences overall?” Ask “How many ways can I build THIS prefix of t?” Build prefix → reach full answer. 🎯 Lesson When counting problems appear: Think in terms of: • Choices (take / skip) • Prefix building • Accumulating ways That’s DP in its purest form. Day by day getting sharper 💪 From solving → to understanding patterns 🚀 Consistency continues. Follow for more DSA breakdowns 🔥 #LeetCode #DSA #DynamicProgramming #InterviewPrep #CodingJourney #ProblemSolving #100DaysOfCode #SoftwareEngineering #TechGrowth
To view or add a comment, sign in
-
-
DSA Cheat Sheet for Developers Master Data Structures & Algorithms Fast Boost your problem-solving skills with this complete DSA Cheat Sheet designed for developers! Covering essential data structures, algorithms, time complexity, sorting, searching, recursion, trees, graphs, and dynamic programming — this quick reference helps you revise faster and code smarter. Perfect for coding interviews, competitive programming, and strengthening your programming fundamentals. #DSA #DataStructures #Algorithms #DSACheatSheet #CodingInterview #ProblemSolving #Programming #Developers #TechLearning #SoftwareEngineering #CompetitiveProgramming #InterviewPreparation #Coding #LearnToCode
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