🗓 Day 8 / 100 – #100DaysOfLeetCode 📌 Problem 474: Ones and Zeroes The task was to determine the largest subset of binary strings that can be formed using at most m zeros and n ones — essentially a two-dimensional 0/1 Knapsack problem. 🧠 My Approach (in Java): Counted the number of zeros and ones in each string. Used a 2D DP array dp[m][n] to store the maximum subset size possible with given zeros and ones. Iterated in reverse order to ensure each string is only used once (knapsack-style update). Updated states using dp[i][j] = max(dp[i][j], dp[i - zeros][j - ones] + 1). ⏱ Time Complexity: O(len(S) × M × N) 💾 Space Complexity: O(M × N) 💡 Key Learning: This problem strengthened my understanding of multi-dimensional DP — especially how to translate real-world constraints into DP states. It’s a great reminder that mastering DP isn’t about memorizing patterns but about building intuition on state transitions and decisions. Consistent effort. Deep learning. Step by step 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Java #DynamicProgramming #Knapsack #Algorithms #ProblemSolving #DataStructures #DSA #CodingJourney #CompetitiveProgramming #SoftwareEngineering #LearningInPublic #DeveloperJourney #TechStudent #LogicBuilding #CodingCommunity #CodeEveryday #CareerGrowth #Optimization #KeepLearning
Solved 474: Ones and Zeroes with Java DP
More Relevant Posts
-
🚀 Day 35 of 100 Days of LeetCode 📘 Problem: Binary Tree Inorder Traversal 💻 Language: Java ✅ Status: Accepted — Runtime ⚡ 1 ms Today’s focus was on mastering tree traversal, one of the most essential techniques in data structures 🌳 The goal was simple — visit nodes in order (Left → Root → Right), but the recursive logic behind it reinforced clarity and structured thinking. ✨ Key Learnings: Recursive approach simplifies traversal logic 🧠 Base cases are the backbone of recursion Understanding tree patterns helps in mastering complex problems like BSTs and DFS 💬 “A binary tree teaches one thing — structure leads to clarity.” #Day35 #100DaysOfCode #LeetCode #Java #BinaryTree #Recursion #ProblemSolving #DSA #CodingJourney #SoftwareDevelopment #KeepLearning
To view or add a comment, sign in
-
-
💡 Day 31/100 Days Today’s problem was “Valid Palindrome” 🪞 The challenge was to check if a string reads the same forward and backward after removing all non-alphanumeric characters and ignoring case differences. This helped strengthen my understanding of string manipulation and the two-pointer technique in Java. 🧠 Key Features: Cleaned the string using regex to remove unwanted characters. Applied two-pointer logic to compare characters from both ends. Simple, efficient, and elegant — a great example of how logic matters more than length of code. ⚙️ Time Complexity: O(n) → Each character checked once. 💾 Space Complexity: O(n) → For the cleaned string (or O(1) in in-place approach). ✨ Takeaway: This problem reinforced how small optimizations — like using pointers instead of extra data structures — make algorithms more efficient. Every problem is a step closer to cleaner and smarter code! #Day31Of100 #DSA #Java #ProblemSolving #TwoPointer #CodingJourney #100DaysOfCode #LearningEveryday
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode 💻 Today, I solved LeetCode Problem #709 – To Lower Case 🔠 This problem focuses on string manipulation and character encoding (ASCII values) — one of the simplest yet fundamental concepts in text processing. 💡 Key Learnings: Reinforced understanding of ASCII value ranges for uppercase and lowercase alphabets. Practiced efficient string traversal and conditional conversion using StringBuilder in Java. Time complexity: O(n) — iterates through the string once. Space complexity: O(n) — for the output string. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100% 🚀 📉 Memory: 41.78 MB — Beats 43.48% 🧠 Approach: 1️⃣ Iterate through each character in the string. 2️⃣ Check if it’s an uppercase letter (A–Z). 3️⃣ Convert it to lowercase by adding 32 (based on ASCII values). 4️⃣ Append to the final string using StringBuilder. ✨ Takeaway: Sometimes, understanding the basics like ASCII values can help you write your own efficient methods — without relying on built-in functions! #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #Algorithms #StringManipulation #SoftwareEngineering #LearningEveryday #CleanCode
To view or add a comment, sign in
-
-
Day 50 / 100— DSA From Scratch (Medium) Problem Solved: Construct Binary Tree from Preorder and Inorder Traversal Task: Rebuild a binary tree using the given preorder and inorder traversal arrays. Approach Used: Used a recursive divide-and-conquer approach. The first element in the preorder array represents the root. Found the root’s position (mid) in the inorder array — everything to its left forms the left subtree, and everything to its right forms the right subtree. Used Arrays.copyOfRange() to split both arrays for recursive calls. Initially, I was stuck thinking about the algorithm — how to connect preorder and inorder logically — but once I saw how the recursion works, it became very clear. Also, I learned a new method — the copyOfRange() function in Java, which helped simplify array slicing during recursion. Complexity: Time Complexity: O(n²) — due to searching for the root index each time. Space Complexity: O(n²) — because of repeated array slicing. Reflection: This problem taught me more than just recursion — it showed how traversal patterns can reconstruct an entire tree when understood properly. Every problem like this builds not just coding skills but also clarity in algorithmic thinking. #Day50 #DSAFromScratch #BinaryTree #Preorder #Inorder #Recursion #Java #ProblemSolving #LeetCode #LearningEveryday #100DaysOfCode
To view or add a comment, sign in
-
-
💻 Day 4 of #100DaysOfCode Challenge Topic: Binary Tree Traversals 🌳 Problems Solved: 🔹 94. Binary Tree Inorder Traversal 🔹 144. Binary Tree Preorder Traversal 🔹 145. Binary Tree Postorder Traversal Concept Recap: Today, I explored the three fundamental depth-first traversal techniques used in binary trees: ✅ Inorder (Left → Root → Right) – Produces a sorted order for BSTs. ✅ Preorder (Root → Left → Right) – Useful for creating a copy of the tree or serialization. ✅ Postorder (Left → Right → Root) – Ideal for deleting trees or evaluating expressions. Each traversal follows a recursive approach to explore nodes systematically. Implementing them helped me strengthen my understanding of recursion and how stack frames manage function calls behind the scenes. Key Learnings: 🧠 Understood how traversal order impacts output sequence. ⚙️ Practiced recursive depth-first traversal logic in Java. 🌱 Improved code readability by modularizing recursive functions. #LeetCode #DataStructures #BinaryTree #Recursion #Java #CodingChallenge #100DaysChallenge #Day4
To view or add a comment, sign in
-
-
Day 37/100 ✅ Binary Tree Postorder Traversal Today I solved the Binary Tree Postorder Traversal problem using a simple recursive approach in Java. In postorder traversal, we visit nodes in the order Left → Right → Root. This helps in many real-world tree-based algorithms like expression tree evaluations or file system traversal. 💡 Approach: I used recursion — first visiting the left child, then the right child, and finally adding the node’s value to the result list. It’s clean, elegant, and easy to understand! ✅ Key Learning: Understanding traversal patterns (Preorder, Inorder, Postorder) is essential for mastering tree-based problems. Each pattern teaches how to process data at different stages of recursion. #LeetCode #Java #CodingJourney #DSA #BinaryTree #Recursion #PostorderTraversal #100DaysOfCode
To view or add a comment, sign in
-
-
Today, I explored how Depth First Search (DFS) works in Java by solving the “All Paths from Source to Target” problem. At first, I faced challenges like managing the same reference of path lists and understanding how backtracking actually restores the previous state. But once I understood the flow of recursion — adding, exploring, and removing nodes — everything clicked. Here’s what I learned: ✅ Always clone or backtrack when tracking paths in recursion. ✅ Understanding the call stack flow is key to debugging DFS. ✅ Visualizing the recursion tree helps a lot when things get confusing. Now, I can confidently trace how each path is built and how DFS explores all possible routes in a graph. Small wins like this make the journey of learning algorithms so rewarding! #Java #DSA #GraphAlgorithms #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 60 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #137 – Single Number II 🧩 📘 Problem Statement: Given an integer array where every element appears three times except for one that appears exactly once, find that single element and return it. The challenge: solve it with O(n) time and O(1) space complexity. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% 📉 Memory: 45.54 MB — Beats 56.30% 🧠 Concept Used: 🔹 Bit Manipulation — A powerful yet tricky technique that leverages binary operations to track occurrences of bits efficiently. 🔹 Instead of using extra space or hash maps, we track bits that appear once and twice using two integer variables: ✅ once → bits that appeared once ✅ twice → bits that appeared twice The trick lies in updating them using XOR (^) and NOT (~) to "cancel out" bits appearing three times. 🧩 Approach Summary: 1️⃣ Initialize two variables once = 0 and twice = 0. 2️⃣ For every number in the array: - Update once and twice based on how many times a bit has appeared. 3️⃣ After processing all numbers, once holds the value of the single element. ✅ Complexity: Time: O(n) Space: O(1) ✨ Takeaway: This problem teaches how bitwise logic can replace traditional data structures, achieving the same result with constant space — a crucial optimization in system-level programming and interviews. #100DaysOfCode #LeetCode #Java #BitManipulation #ProblemSolving #CleanCode #DataStructures #Algorithms #TechLearning #CodingChallenge #SoftwareEngineering #InterviewPreparation
To view or add a comment, sign in
-
-
💻 Day 75 of #100DaysOfCodingChallenge ✨ Problem: 560. Subarray Sum Equals K 📚 Category: Array Manipulation | Subarray Problems 💡 Approach: Brute Force 🧠 Language: Java 🔍 Problem Understanding: We’re given an integer array nums and an integer k. We need to count how many subarrays (continuous parts of the array) have a sum equal to k. Example: Input: nums = [1, 2, 3], k = 3 Output: 2 Explanation: [1,2] and [3] are the subarrays with sum 3. 🧠 Brute Force Approach: In the brute-force method, we check every possible subarray using two loops: 1️⃣ Start from each element as a subarray beginning. 2️⃣ Keep adding elements until the end, and check if the sum equals k. 3️⃣ If yes, increment the count. Although it’s not the most optimized, this approach helps build a strong foundation in understanding subarray logic. ⚙️ Complexity: Time Complexity: O(n²) Space Complexity: O(1) 🌱 Learning: This problem taught me how to approach subarray-based questions step-by-step — starting from brute force before moving toward optimized solutions like prefix sums + hashmaps. Building clarity in fundamentals always makes optimization easier later 🚀 #Day75 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #WomenInTech #DSA #ArrayManipulation
To view or add a comment, sign in
-
-
🚀 Day 14 — Data Structures & Algorithms in Java 🔹 Topic: First Unique Character in a String (Using HashMap) Today, I explored how to identify the first non-repeating character in a given string using HashMap — an efficient and flexible approach that works for all character types. 💡 Concept We store each character’s frequency in a HashMap, then find the first index with frequency 1. 🧠 Example 📥 Input: "loveleetcode" 📤 Output: 2 (Character 'v' is the first unique one) ⚙️ Complexity ⏱ Time: O(n) 💾 Space: O(n) ✨ Key Takeaway HashMaps are incredibly powerful for frequency-based problems — offering both simplicity and efficiency in solving string and array challenges. #Java #Coding #30DaysOfCode #LeetCode #DSA #ProblemSolving #LearningJourney #WomenInTech #1000coders
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
Be Consistent champ :)