🚀 Day 50 of #365DaysOfCode – LeetCode Practice Github link: https://lnkd.in/gGUy_MKZ Today I solved the problem “Count Binary Substrings.” The challenge was to count the number of non-empty substrings in a binary string that contain an equal number of 0s and 1s, with all identical digits grouped consecutively. Instead of checking all possible substrings (which would be inefficient), I learned an important pattern: 🔹 Valid substrings are formed between consecutive groups of 0s and 1s. 🔹 The number of valid substrings between two groups is determined by 👉 min(size of previous group, size of current group) This approach helped reduce the time complexity to O(n) with O(1) space. 💡 Key Takeaway: Sometimes the optimal solution comes from observing patterns in grouping rather than brute-force substring checking. Consistency in problem-solving is sharpening my understanding of patterns and optimization every day 📈 #Java #DSA #LeetCode #ProblemSolving #CodingJourney #BitManipulation
LeetCode Day 50: Count Binary Substrings with Efficient Pattern
More Relevant Posts
-
Day 8 Today I solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode. At first glance, the problem looks simple: Given a binary string, check whether it contains only one continuous segment of '1's. Example: "110" → Valid (one segment of 1s) "1001" → Invalid (two separate segments of 1s) While solving it, I realized an interesting observation: 👉 If a binary string has more than one segment of 1s, the pattern "01" must appear before another "1". So instead of counting segments explicitly, we can simply check whether '01' appears and is followed by another '1'. This turns the problem into a very efficient linear scan with O(n) time complexity. 💡 Key takeaway: Sometimes the simplest solution comes from recognizing patterns in the string rather than simulating the whole process. Also happy to see my solution running at 0 ms runtime (100% faster) 🚀 #LeetCode #DSA #ProblemSolving #Java #CodingJourney #BinaryStrings
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day38 📌 LeetCode – Power of Two Today I solved the Power of Two problem using two different approaches and explored the power of bit manipulation. 🔍 Problem Summary: Given an integer n, return true if it is a power of two. Otherwise, return false. 💡 Key Insight: A power of two always has only one set bit (1) in its binary representation. For example: 1 → 0001 2 → 0010 4 → 0100 8 → 1000 Used the bit manipulation trick: (n & (n - 1)) == 0. This makes the solution run in O(1) time. Also tried the division approach for better understanding. Bitwise concepts are becoming clearer day by day. Consistency is the real key to mastery 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #TechGrowth #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 20/60 Completed – LeetCode Problem of the Day Challenge Today’s challenge: Check if Binary String Has at Most One Segment of Ones The problem asks us to determine whether a binary string contains at most one continuous segment of '1's. 🧠 Approach & Key Learnings: • Traversed the string once from left to right. • Once a segment of '1's starts, we track it. • If we encounter '0' after the first segment of '1's, we mark that a break occurred. • If another '1' appears after that zero, it means there is more than one segment of ones → return false. • Otherwise, the string contains only one contiguous segment of ones → return true. ⚙️ Key Concepts Practiced: • String traversal • Segment detection in binary strings • Boolean flag tracking • Writing clean linear-time logic Small problem, but a good exercise in carefully tracking patterns while scanning a string. 20 days down. Consistency is getting stronger every day. ⚡ 40 days to go — staying locked in. 🔥 #LeetCode #60DaysChallenge #ProblemOfTheDay #DSA #Java #CodingJourney #Consistency #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 27 of My LeetCode Journey 📌 Problem: Maximum Product of Three Numbers (LeetCode 628) Today’s challenge was to find the maximum product of any three numbers in an integer array. The important observation is that the maximum product can come from: • The three largest numbers, or • The two smallest numbers (negative values) multiplied by the largest number. 🧠 Approach Used: Single Pass (Tracking Maximum & Minimum Values) Instead of sorting the array, we iterate through the array once and keep track of: The three largest numbers The two smallest numbers Finally, we compute the maximum between: 1️⃣ max1 × max2 × max3 2️⃣ min1 × min2 × max1 ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This approach avoids sorting and efficiently finds the result in a single traversal of the array. #Day27 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 11 of #Leetcode75 LeetCode #392 – Is Subsequence | Two Pointer Approach Today I solved “Is Subsequence” (Easy) and revised an important concept — the Two Pointer Technique. 🔎 Problem Summary: Given two strings s and t, determine whether s is a subsequence of t. A subsequence maintains the relative order of characters but doesn’t need to be continuous. 💡 Key Insight: Instead of using extra space or complex logic, we can solve this efficiently using two pointers: ✔ One pointer for s ✔ One pointer for t ✔ Move forward and match characters in order ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This problem reinforces how powerful simple logic can be when applied correctly. Consistency > Complexity 💪 Excited to keep improving step by step! #LeetCode #DSA #Java #CodingPractice #ProblemSolving #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 12/100 – Plus One. Today I solved the Plus One problem on LeetCode. 🔹 Problem Statement: Given an array of digits representing a non-negative integer, increment the number by one and return the resulting array. 🔹 Approach: I traversed the array from right to left (last digit to first). If the current digit is less than 9 → simply increment it and return the array. If the digit is 9 → make it 0 (because 9 + 1 = 10, carry generated). If all digits are 9 → create a new array of size n + 1, put 1 at the beginning, and return it. 🔹What I Learned : How to handle carry when adding 1 to a number stored as an array. Why we iterate from right to left while working with digits. How to manage the edge case when all digits are 9 (like [9] → [1,0]). That sometimes we need to create a new array with extra space to store the result. Improved understanding of array manipulation and conditional logic in Java. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) (except when a new array is needed). #Day12 #100DaysOfCode #LeetCode #Java #DSA #Consistency
To view or add a comment, sign in
-
-
Day 18 – Same Tree 🚀 Continuing my DSA journey with Striver’s A2Z Sheet / LeetCode practice. Today’s problem focused on checking whether two binary trees are identical, which is a classic tree recursion problem. Approach We compare both trees node by node using recursion. At each step: 1️⃣ If both nodes are null → trees match 2️⃣ If one is null → not same 3️⃣ If values differ → not same 4️⃣ Recursively check left and right subtrees Time Complexity : O(N). Space Complexity : O(N) . Github Code :- https://lnkd.in/guF5Vq9m #LeetCode #DSA #StriverA2Z #CodingJourney #Java #BinaryTree #Recursion #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #Day18 #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge 🧩 Problem: 1784 – Check if Binary String Has at Most One Segment of Ones Today’s problem looked confusing at first. Honestly, the problem description wasn’t very intuitive, and I had to read it a couple of times to understand what it was actually asking. 💡 What the question really means: We’re given a binary string without leading zeros, and we need to check if all the 1s appear in only one continuous block. Valid examples: 111 110 1000 Invalid example: 1001 → because the 1s appear in two separate segments So the key idea is simple: If the string ever contains the pattern "01", it means we finished a block of 1s and then encountered another 1 later — which creates multiple segments. ⚡ Approach Just check if "01" exists in the string. If it does → return false Otherwise → return true 🧠 Takeaway Sometimes the hardest part of a problem isn’t the coding — it’s understanding the problem statement clearly. Once the logic clicked, the solution became very straightforward. Consistency with daily problem solving continues. 🔁 #LeetCode #DailyChallenge #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
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