Solved LeetCode problem 1513: Counting 1s substrings with efficiency

🗓 Day 13 / 100 – #100DaysOfLeetCode 📌 Problem 1513: Number of Substrings With Only 1s The task was to count how many substrings in a binary string consist only of consecutive 1s. 🧠 My Approach: Identified continuous blocks of '1' in the string. For each block of length k, calculated the number of valid substrings using the formula: k × (k + 1) / 2 Summed these counts across all segments of consecutive 1s. This avoids checking all substrings individually and keeps the solution efficient and clean. 💡 Key Learning: This problem reinforces the value of recognizing sequences and using mathematical formulas to simplify substring counting. It’s a reminder that many problems can be solved much faster when we look for structure instead of brute force. One more problem, one more pattern learned 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Strings #Algorithms #MathInCoding #LogicBuilding #DataStructures #DSA #CompetitiveProgramming #CodingJourney #SoftwareEngineering #LearningInPublic #DeveloperJourney #TechStudent #CareerGrowth #CodeEveryday #CodingCommunity #KeepLearning

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories