Solved LeetCode problem using Sliding Window and Two Pointers in Java.

Day 54/100 – #100DaysOfCode 🚀 | #Java #SlidingWindow #TwoPointers ✅ Problem Solved: Count the Number of Substrings With Dominant Ones (LeetCode) 🧩 Problem Summary: You’re given a binary string. A substring is dominant if: number of 1s > number of 0s × k (where k is given). Return the total count of such substrings. 💡 Approach Used: Used an optimized Sliding Window + Two Pointers approach: Traverse with a right pointer. Adjust the left pointer whenever the substring stops being dominant. All valid windows contribute (left + 1) substrings. This avoids brute-force O(N²) and makes the solution efficient. ⚙️ Time Complexity: O(N) 📦 Space Complexity: O(1) ✨ Takeaway: Sliding window transforms heavy substring problems into clean linear-time solutions. #Java #LeetCode #SlidingWindow #TwoPointers #ProblemSolving #CodingChallenge #100DaysOfCode

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories