📌 Day 20/100 – Add Binary (LeetCode 67) Today’s challenge was about adding two binary strings and returning the result in binary format — just like simulating manual binary addition with carry logic. 🔹 Problem: Given two binary strings a and b, return their sum as a binary string without converting them into decimal. 🔹 Approach: Start from the end of both strings (like column-wise addition). Use a carry variable to handle overflow (0 or 1). Keep appending the result (sum % 2) to a StringBuilder. Reverse the string at the end since we append from LSB to MSB. 🔹 Key Learnings: StringBuilder is more efficient than string concatenation in Java. Handling indices carefully avoids edge-case bugs. Binary addition logic is similar to decimal addition — just base changes, logic stays. #100DaysOfCode #Day20 #LeetCode #Java #BinaryMath #DSA #ProblemSolving #CodingJourney #KeepLearning
Adding Binary Strings with Carry Logic in Java
More Relevant Posts
-
🚀Day 99/100 #100DaysOfLeetCode 🔍Problem: Sum of Two Integers✅ 💻Language: Java 💡Approach: Instead of using the ‘+’ or ‘–’ operators, this problem leverages bit manipulation to perform addition. 🔸Use XOR (^) to calculate the sum without carry. 🔸Use AND (&) followed by a left shift (<< 1) to calculate the carry. 🔸Repeat until no carry remains. 📚Key Takeaways: 🔹Reinforced understanding of bitwise operations. 🔹Learned how addition can be simulated using logical operations. 🔹Improved understanding of low-level arithmetic computation. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 40.88 MB (Beats 10.05%) #100DaysOfLeetCode #Java #BitManipulation #CodingChallenge #ProblemSolving #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
✅ Day 57/100 — LeetCode Challenge Problem: Transpose Matrix Language: Java Today I worked on a classic matrix operation — transposing a matrix. The goal is to convert rows into columns and vice-versa. This problem reinforced my understanding of 2D arrays and index manipulation in Java. 💡 Key Idea: If matrix has dimensions m x n, the transpose will have dimensions n x m, and each element at (i, j) becomes (j, i). 📌 Approach: Calculate row & column length Create result matrix with swapped dimensions Iterate & swap positions accordingly #100DaysOfCode #LeetCode #Java #DSA #Matrix #TechJourney #CodingChallenge #SoftwareEngineering #LearningEveryday
To view or add a comment, sign in
-
-
🔥 #100DaysOfDSA — Day 30/100 Topic: Reverse an Array in Java 🔁 💡 What I Did Today: Today, I explored how to reverse an array manually using the two-pointer approach. Instead of relying on built-in methods, I learned how to swap elements from both ends until the array is completely reversed. 🧠 Logic Used: Initialize two pointers: start = 0 (beginning of array) end = numbers.length - 1 (end of array) While start < end: Swap numbers[start] and numbers[end] Move pointers inward → start++ and end-- 📊 Example: Input → {2, 4, 6, 8, 10} Output → {10, 8, 6, 4, 2} ⚙️ Time Complexity: O(n) — each element is swapped once. O(1) space — done in-place without using extra arrays. ✨ Takeaway: Learning to reverse an array manually helps strengthen the concept of pointers, loops, and in-place operations. Sometimes the simplest logic gives the biggest "aha!" moment 💡 #100DaysOfCode #Day30 #Java #DSA #Arrays #ProblemSolving #CodingJourney #LearnInPublic #DeveloperLife #CodeNewbie #LogicBuilding
To view or add a comment, sign in
-
-
#Day-68) LeetCode #3228 – Maximum Number of Operations to Move Ones to the End (Java Edition) Tackled this neat string problem using a greedy approach in Java. The challenge? Move '1's to the end of the string under specific movement rules, maximizing the number of valid operations. 🧠 Core Idea: Track how many '0's we've seen and how many '1's we've already moved. Only move a '1' if there's enough '0's to justify it and the next character is also '1'. 💻 Java Strategy: Loop through the string Use counters to manage '0's and '1's Let me know how you'd tweak this or if you see a more optimal path! #Java #LeetCode #GreedyAlgorithm #StringProblems #DSA #CodingChallenge #LinkedInTech #ProblemSolving
To view or add a comment, sign in
-
-
🌟 Day 94 of 100 Days of Code 🌟 Today’s challenge: Maximum Number of Operations to Move Ones to the End (LeetCode 3228) 💡 🧠 Problem: Given a binary string, you can repeatedly move '1' to the right (until it meets another '1' or the end). The goal is to find the maximum number of such operations possible. ⚙️ Approach: Traverse the string once. Track the count of '1's and increment operations based on '10' patterns. Efficient O(n) solution using simple logic and character comparisons. ✅ Result: ✔️ All test cases passed ⚡ Runtime: 7 ms — Beats 78.52% of Java submissions #100DaysOfCode #Day94 #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms #CodeEveryday
To view or add a comment, sign in
-
-
🚀Day 96/100 #100DaysOfLeetCode 🧩Problem: Reverse Linked List II✅ 💻Language: Java 💡 Approach: 1️⃣ First, use a dummy node to handle edge cases where reversal starts at the head. 2️⃣ Traverse to the node just before the left position — call it prev. 3️⃣ Reverse the sublist between left and right using standard pointer manipulation. 4️⃣ Reconnect the reversed portion back into the original list. 🔑Key Takeaways: 🔹Dummy nodes simplify linked list edge cases. 🔹In-place reversal reduces memory overhead. 🔹Careful pointer tracking ensures list integrity. ⚙️Performance: ⏱️Runtime: 0 ms(beats 100.00%) 💾Memory: 41.29 MB(beats 70.37%) #100DaysOfLeetCode #Java #LinkedList #CodingJourney #ProblemSolving #DSA #LeetCode #CodingChallenge
To view or add a comment, sign in
-
-
#Day-69) LeetCode 2536: Increment Submatrices by One using a 2D difference array technique in Java — a powerful approach for handling multiple range updates efficiently. 🔧 Instead of brute-force iteration over each query, I used a prefix sum strategy to apply all updates in constant time per query, followed by a cumulative pass to build the final matrix. 🧠 Highlights: Efficient submatrix updates using difference matrix Prefix sum accumulation for final values Clean, scalable Java implementation 📌 This kind of problem is a great reminder: smart preprocessing beats brute force. Let’s connect if you’ve explored similar matrix tricks or want to brainstorm more Java optimizations! #Java #LeetCode #DSA #MatrixOptimization #CodingInPublic #ProblemSolving #TechJourney #LinkedInTech
To view or add a comment, sign in
-
-
🚀Day 23/100- Problem of the day:- Next Greater Numerically Balanced Number. 🧩 Goal: To determine whether a given number is digit-count balanced — meaning each digit appears exactly as many times as its own value. 💡 Core Idea: Convert the number to a string, count the frequency of each digit, and then check if each digit’s frequency matches its numeric value. If all match, the number is balanced. 🔑 Key Takeaway: This problem emphasizes understanding of digit manipulation, frequency counting, and validation logic using simple array-based frequency mapping — a great exercise for strengthening logic building and string-handling skills in Java. 💾 Space Complexity: O(1) — constant extra space (only frequency array of size 10). ⏱ Time Complexity: O(n) — where n is the number of digits in the given number. #100DaysChallenge #Java #DSA #Leetcode #Day23 #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 6: C#: Continued with unit testing and learned a bit more about coverage evaluation using .Net, I used extension methods few times which a cool feature in C#, advantage it let is you add method to a class without modifying the base implementation and without dealing with inheritance. Java: I will play with stream API more and look at my previous notes to continue refactor. AI: I tried to test few ways of doing prompts, used one shot prompt with copilot which can give better result when using agent mode. I plan to work on one blog article per week to share my learning/ review notes. #100DaysOfCode #CSharp #Java #GenAI #ContinuousLearning
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