LeetCode POTD: Counting Substrings With Only 1s

This title was summarized by AI from the post below.
View profile for Vikas Gulia

Software Developer | BCA at IITM Janakpuri | Competitive Programming Winner | Nexverse IITM

🚀 LeetCode POTD — 1513. Number of Substrings With Only 1s 🎯 Difficulty: Medium | Topics: Counting, Math, Sliding Window 🔗 Solution Link: https://lnkd.in/gw_b_eXH Today’s #LeetCode Problem of the Day was a straightforward counting problem — all about finding how many substrings contain only '1' in a binary string. My approach was simple yet efficient: Traverse the string and count consecutive sequences of 1s. For any streak of length n, the number of valid substrings is: n⋅(n+1)2\frac{n \cdot (n + 1)}{2}2n⋅(n+1) After collecting a streak, jump the index forward by count - 1 (since all those characters are already processed). This keeps the solution clean and avoids unnecessary nested checks. 📈 Complexity: Time: O(n) Space: O(1) 💡 Takeaway: Problems like this remind us how far simple math can take you — a clean formula can replace dozens of lines of brute-force logic. #LeetCode #ProblemOfTheDay #Math #StringProcessing #Counting #DSA #CodingChallenge #SoftwareEngineering #CodingJourney #100DaysOfCode #LearningInPublic #TechCommunity

  • text

To view or add a comment, sign in

Explore content categories