Day 13/100 – LeetCode Challenge 🚀 Solved Count Binary Substrings using an optimized O(n) approach by grouping consecutive characters and comparing segment lengths. Key takeaway: Instead of generating all substrings, identify patterns and reduce the problem to counting adjacent groups. Consistency > Motivation 💪 #100DaysOfCode #DSA #Java #LeetCode
Optimized LeetCode Challenge: Count Binary Substrings in O(n)
More Relevant Posts
-
Day 30/100 – LeetCode Challenge 🚀 Problem: Count Binary Substrings Approach: Counted consecutive groups of 0’s and 1’s For every adjacent pair of groups, added min(prevGroup, currGroup) to the result Avoided generating substrings explicitly Time Complexity: O(n) Space Complexity: O(1) Key takeaway: Many substring problems don’t require generating substrings — they can be solved by analyzing group patterns and transitions. #LeetCode #100DaysOfCode #DSA #Java #Strings #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode Problem || Check if Binary String Has at Most One Segment of Ones(1784)🚀 we need to check: The string should have only one continuous block of '1's. After a '0' appears, '1' should never appear again. ✨ Insight: Instead of manually counting segments using loops, we can simply check if "01" exists in the string. 📌 Time Complexity: O(n) Practicing problems like these helps improve pattern recognition and problem-solving efficiency. #LeetCode #DSA #Java #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day: 71/365 📌 LeetCode POTD: Count Submatrices with Top-Left Element and Sum Less Than k Medium Key takeaways/Learnings from this problem: 1. Prefix sum is the hero here—once you precompute it, submatrix sum becomes instant lookup instead of recomputing every time. 2. Fixing the top-left corner simplifies things a lot, turning a 2D problem into something more manageable. 3. Instead of brute forcing all submatrices, you just expand and check smartly using precomputed sums. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Day 35/100 – LeetCode Challenge 🚀 Problem: 3Sum Approach: Sorted the array Fixed one element and used two pointers for the remaining two Skipped duplicates to ensure unique triplets Used early stopping when the current number became positive Time Complexity: O(n²) Space Complexity: O(1) Key takeaway: Many 3-element sum problems reduce to sorting + two-pointer pattern. #LeetCode #100DaysOfCode #DSA #Java #TwoPointers #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
Day 36/100 – LeetCode Challenge 🚀 Problem: 3Sum Closest Approach: Sorted the array Fixed one element and applied the two-pointer technique Tracked the closest sum by comparing absolute differences Returned immediately if an exact match was found Time Complexity: O(n²) Space Complexity: O(1) Key takeaway: Many optimization problems are variations of classic patterns. Understanding 3Sum deeply makes solving 3Sum Closest straightforward. #LeetCode #100DaysOfCode #DSA #Java #TwoPointers #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
Day: 72/365 📌 LeetCode POTD: Count Submatrices With Equal Frequency of X and Y Medium Key takeaways/Learnings from this problem: 1. The key idea is converting the problem into numbers (like +1 and -1) so equal frequency turns into a sum = 0 problem. 2. 2D prefix sums really help here—you can quickly get submatrix sums without recalculating every time. 3. It’s a nice extension of 1D subarray problems to 2D, so knowing those basics pays off big time. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 Day 20 – #100DaysOfLeetCode Today’s problem: Product of Array Except Self (Medium) 🔹 Learned how to solve it in O(n) time 🔹 Without using division 🔹 Optimized space complexity The key idea was using prefix and suffix products instead of recalculating product every time. #Day20 #LeetCode #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Problem || Prime Number of Set Bits in Binary Representation(762)🚀 Solved an interesting bit manipulation problem today! Problem : Given two integers left and right, count how many numbers in that range have a prime number of set bits (1s) in their binary representation. This problem shows how: Binary representation connects with number theory Built-in methods like bitCount() simplify bit problems Constraint analysis helps optimize thinking Small problems like this build strong fundamentals in bit manipulation. #LeetCode #Java #BitManipulation #PrimeNumbers #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 20/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 350. Intersection of Two Arrays II Used sorting + two-pointer technique to efficiently find common elements appearing in both arrays while maintaining correct frequency. ⏱️ Time Complexity: O(n log n + m log m) 📦 Space Complexity: O(min(n, m)) (for storing the intersection) Strengthening understanding of array traversal and two-pointer pattern through consistent practice. 💪 Consistency keeps the progress moving 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 9/100 – LeetCode Challenge Problem: 3Sum Today’s challenge was to find all unique triplets in an array whose sum equals 0. Approach: Sort the array to efficiently apply the two-pointer technique. Fix one element nums[i] and use two pointers (left and right) to find the remaining two numbers. If the sum equals 0, store the triplet. Skip duplicate elements to ensure only unique triplets are included. Key Idea: Sorting + Two Pointers helps reduce the brute-force O(n³) approach to O(n²). Concepts Practiced: Sorting Two-pointer technique Duplicate handling Array traversal optimization #100DaysOfCode #LeetCode #DSA #Java #TwoPointers #ProblemSolving #CodingJourney
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
wish you the very best