🔹 Day 31: Add Binary (LeetCode #67) 📌 Problem Statement: Given two binary strings a and b, return their sum as a binary string. ✅ My Approach: Simulated binary addition manually using a carry-based approach. Started from the end of both strings, added corresponding bits along with the carry, appended the remainder (sum % 2) to the result, and updated the carry (sum / 2). Finally, reversed the result string to get the correct binary sum. 📊 Complexity: Time Complexity: O(max(n, m)) Space Complexity: O(max(n, m)) ⚡ Submission Stats: Runtime: 1 ms (Beats 99.71%) Memory: 42.45 MB 💡 Reflection: This problem strengthened my understanding of bitwise addition and string manipulation — a perfect mix of logic and implementation precision! ⚙️ #LeetCode #Java #String #Binary #100DaysOfCode #Day31
Adding Binary Strings with Carry-Based Approach
More Relevant Posts
-
#100DaysOfCode – Day 68 String Manipulation Problem 1:- Largest Odd Number in String Task:- Given a numeric string, return the largest-valued odd number (as a substring) or an empty string if none exists. Example: Input: num = "35427" → Output: "35427" My Approach: Started scanning the string from right to left. The first odd digit encountered marks the end of the required substring. Returned the substring from start to that index. Time Complexity:- O(N) Space Complexity:- O(1) Sometimes, it’s not about complex algorithms just a small logical observation can lead to an efficient solution. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #CodeNewbie #StringManipulation #LogicBuilding #CleanCode
To view or add a comment, sign in
-
-
🌟 Day 92 of #100DaysOfLeetCode — Shuffle String (LeetCode 1528) Today’s problem was a simple yet elegant string manipulation challenge — “Shuffle String”, which tests your ability to rearrange elements based on given indices. 🧩 Problem: We are given a string s and an integer array indices. Each character in s should be placed at the new position given by indices[i]. The goal is to return the newly shuffled string. 🧠 Logic: Create a character array result of the same length as s. Loop through each index i. Place s.charAt(i) in result[indices[i]]. Finally, return the new string formed from result. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) 💬 This problem reminded me how simple array manipulation techniques can efficiently solve string rearrangement tasks — a great warm-up for more complex mapping problems! #Day92 #LeetCode #100DaysOfCode #Java #ProblemSolving #CodingJourney #WomenInTech
To view or add a comment, sign in
-
-
✅ Day 32 of #100DaysOfCode Challenge 📘 LeetCode Problem 108: Convert Sorted Array to Binary Search Tree 🧩 Problem Statement: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). A height-balanced BST ensures both left and right subtrees of every node differ in height by at most 1. 💡 Simple Idea: Pick the middle element as the root. Elements on the left become the left subtree. Elements on the right become the right subtree. Repeat the same steps recursively. ⚙️ Complexity: ⏱️ Time: O(n) 💾 Space: O(log n) (recursion stack height) 🌱 Step by step, building balance in both code and logic! #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinarySearchTree #Recursion #CodingChallenge
To view or add a comment, sign in
-
-
✨ Day 58 of 100: Partition List ✨ Today’s challenge was LeetCode 86 – Partition List 🧩 Problem Statement: Given the head of a linked list and a value x, partition it such that all nodes with values less than x come before nodes with values greater than or equal to x. The relative order of nodes in each partition should remain the same. 💡 Key Takeaways: 🔹 Practiced two-pointer technique to maintain separate lists for nodes < x and ≥ x. 🔹 Improved understanding of in-place linked list manipulation. 🔹 Strengthened grasp of dummy node usage to simplify edge cases. 🧠 Approach: 1️⃣ Create two dummy lists – one for smaller nodes and one for greater/equal nodes. 2️⃣ Traverse the original list and link nodes accordingly. 3️⃣ Finally, connect the smaller list’s tail to the head of the greater list. 🔥 Learning: This problem reinforced how clean list partitioning can be done efficiently with dummy nodes and careful pointer handling — all in O(n) time and O(1) extra space! #100DaysOfCode #Day58 #LeetCode #Java #LinkedList #CodingChallenge #ProblemSolving #DSA #PartitionList
To view or add a comment, sign in
-
-
🔹 Day 46: Is Subsequence (LeetCode #392) 📌 Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is formed by deleting some (possibly none) characters from the original string without disturbing the relative order of the remaining characters. ✅ My Approach: I used a two-pointer technique — one pointer iterates through string t, and the other tracks progress through string s. Each time a matching character is found, the pointer for s moves forward. If we reach the end of s, it means all its characters appeared in sequence within t. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 2 ms (Beats 68.53%) Memory: 41.32 MB (Beats 87.28%) 💡 Reflection: A simple yet elegant problem that highlights how pointer movement can efficiently handle string comparisons without extra memory usage. ✨ #LeetCode #Java #Strings #TwoPointers #100DaysOfCode #Day46
To view or add a comment, sign in
-
-
✅ Day 32 of #100DaysOfCode Challenge 📘 LeetCode Problem 108: Convert Sorted Array to Binary Search Tree 🧩 Problem Statement: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). A height-balanced BST ensures both left and right subtrees of every node differ in height by at most 1. 💡 Simple Idea: Pick the middle element as the root. Elements on the left become the left subtree. Elements on the right become the right subtree. Repeat the same steps recursively. ⚙ Complexity: ⏱ Time: O(n) 💾 Space: O(log n) (recursion stack height) 🌱 Step by step, building balance in both code and logic! #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinarySearchTree #Recursion #CodingChallenge
To view or add a comment, sign in
-
-
✅ Day 32 of #100DaysOfCode Challenge 📘 LeetCode Problem 108: Convert Sorted Array to Binary Search Tree 🧩 Problem Statement: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). A height-balanced BST ensures both left and right subtrees of every node differ in height by at most 1. 💡 Simple Idea: Pick the middle element as the root. Elements on the left become the left subtree. Elements on the right become the right subtree. Repeat the same steps recursively. ⚙ Complexity: ⏱ Time: O(n) 💾 Space: O(log n) (recursion stack height) 🌱 Step by step, building balance in both code and logic! #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinarySearchTree #Recursion #CodingChallenge
To view or add a comment, sign in
-
-
🌳 Day 60 of #100DaysOfCode 🌳 🔹 Problem: Balanced Binary Tree – LeetCode ✨ Approach: Used a post-order DFS traversal to calculate subtree heights while checking balance at every node. If the height difference of any subtree exceeds 1, return -1 immediately for an early exit — efficient and elegant! ⚡ 📊 Complexity Analysis: Time: O(n) — each node visited once Space: O(h) — recursion stack space, where h is the tree height ✅ Runtime: 0 ms (Beats 100%) ✅ Memory: 44.29 MB 🔑 Key Insight: A balanced tree isn’t just about equal heights — it’s about smart recursion that detects imbalance early, saving both time and memory. 🌿 #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #Recursion #ProblemSolving #AlgorithmDesign #CodeJourney #ProgrammingChallenge
To view or add a comment, sign in
-
-
🎯 LeetCode 2390 – Removing Stars From a String Today I solved another interesting Stack / String Manipulation problem! 💡 Problem Summary: You’re given a string s containing lowercase letters and *. Each * means you must remove the closest non-star character to its left along with the star itself. Your task is to return the final string after all operations. 🧠 Approach: I used a StringBuilder as a stack to simulate the process. Traverse through the string. If the current character is not *, append it. If it’s *, remove the last added character. Finally, return the resulting string. ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) #LeetCode #Java #DSA #Stack #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 387 of #500DaysOfCode 🧩 LeetCode 476: Number Complement Difficulty: Easy Today’s problem was about flipping all bits of a number’s binary representation to find its complement. For example, 5 → 101 (binary) Complement → 010 = 2 The key idea is to create a bitmask of all 1s having the same length as the binary form of the number and then XOR it with the number — this efficiently flips all bits. 🧠 Approach Summary: 1️⃣ Build a mask with all bits = 1 (same length as num). 2️⃣ Use XOR (^) between num and mask to flip the bits. ✅ Example: num = 5 → 2 num = 1 → 0 Every day, a new concept — one bit at a time ⚙️ #CodingChallenge #LeetCode #Java #ProblemSolving #100DaysOfCode #500DaysOfCode #BitManipulation
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