🗓 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
Solved LeetCode problem 1513: Counting 1s substrings with efficiency
More Relevant Posts
-
Day 30 / 100 – Majority Element II (LeetCode #229) Today’s challenge was all about identifying numbers that appear more than ⌊ n/3 ⌋ times in an array. This problem was a great way to explore the Boyer–Moore Voting Algorithm, an elegant and efficient method to find potential majority elements without using extra space. 🔍 Key Learnings Understanding how counters and candidates evolve in an iterative approach Strengthening logic for pattern recognition and frequency analysis Realizing how efficient algorithms can reduce time and memory usage 💭 Thought of the Day Consistency isn’t just about showing up — it’s about learning smarter each day. Every new problem isn’t a repetition; it’s a refinement of logic and discipline. 🔗 Problem Link:https://lnkd.in/gfiGVueC #100DaysOfCode #Day30 #LeetCode #Python #ProblemSolving #CodingChallenge #DataStructures #Algorithms #LearningJourney #CodeEveryday #TechGrowth
To view or add a comment, sign in
-
-
🗓 Day 12 / 100 – #100DaysOfLeetCode 📌Problem 3234: Count the Number of Substrings With Dominant Ones A substring is considered to have dominant ones if: Number of 1s ≥ (Number of 0s)² The challenge was to count how many substrings in the binary string satisfy this condition. 🧠 My Approach: Iterated through substrings while tracking zero count and one count. Used the condition ones ≥ zeros² to determine validity. Applied early stopping when zeros became large, since the condition becomes much harder to meet as zeros grow. This pruning helped avoid unnecessary checks and made the approach more efficient. 💡 Key Learning: This problem highlights how mathematical constraints can simplify substring evaluation. Understanding how zeros grow quadratically in the condition helped shape a smarter, more optimized checking approach rather than brute-force enumeration. A great exercise in reasoning about substring properties and designing early-exit logic. Consistent effort… consistent progress 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #BinaryStrings #StringAlgorithms #Optimization #LogicBuilding #DataStructures #Algorithms #DSA #CompetitiveProgramming #CodingJourney #SoftwareEngineering #LearningInPublic #TechStudent #DeveloperJourney #CareerGrowth #CodeEveryday #CodingCommunity #KeepLearning #Programmer
To view or add a comment, sign in
-
-
🗓 Day 2 / 100 – #100DaysOfLeetCode 📌 Problem 1636: Sort Array by Increasing Frequency The task was to sort an array such that elements with lower frequency appear first, and if two elements have the same frequency, the larger number comes first. 🧠 My Approach: Counted element frequencies using a hash map. Sorted the elements by ascending frequency and then by descending value. Reconstructed the array based on sorted frequency order. ⏱ Time Complexity: O(n log n) 💾 Space Complexity: O(n) 💡 Key Learning: This problem reinforced how powerful custom sorting logic can be in Python, especially when handling multiple sort priorities using tuple-based keys in sorting functions. Each day is helping me refine how I think about data organization, sorting, and frequency analysis — small steps that build strong foundations. #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Algorithms #DataStructures #DSA #Sorting #CodingJourney #CodingChallenge #SoftwareEngineering #CompetitiveProgramming #CodeEveryday #LearningInPublic #DeveloperJourney #TechStudent #CareerGrowth #CodingCommunity #KeepLearning
To view or add a comment, sign in
-
-
💻 2011: Final Value of Variable After Performing Operations Today’s challenge was a simple yet interesting warm up problem that tests how efficiently we can track changes in a variable through a series of operations. 🧠 Concept: We start with X = 0, and perform operations like ++X, X++, --X, and X--. Each increment or decrement modifies X by 1, the task is to return the final value after performing all operations. ⚙️ Approach: - A straightforward solution: - Iterate through all operations. - Increment count by 1 for ++ or X++. - Decrement count by 1 for -- or X--. - Return the final count. Even though it’s an easy problem, it’s a great reminder that clarity and precision matter, small details in logic can make a big difference. #LeetCode #Python #CodingPractice #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 40 of #100DaysOfDSA Solved LeetCode Problem #69 – Sqrt(x) 🧮 💡 Problem Insight: Given a non-negative integer x, return the square root of x rounded down to the nearest integer. For example: Input: x = 8 Output: 2 (since √8 ≈ 2.828, and floor(2.828) = 2) ✨ Key Learnings: Practiced binary search to find results efficiently without using built-in math functions. Learned how to narrow down search space based on mid-square comparisons. Reinforced understanding of integer division and rounding down behavior. Time Complexity: O(log n) — fast and efficient! Space Complexity: O(1) 💬 Lesson: Binary Search isn’t just for sorted arrays — it’s a mindset for narrowing down possibilities quickly 🚀 #LeetCode #Python #DSA #BinarySearch #ProblemSolving #100DaysOfCode #Day40 #CodingJourney
To view or add a comment, sign in
-
-
#96day of #100DaysOfCode 🌱 LeetCode 109: Convert Sorted List to Binary Search Tree Today’s challenge was about building balance — literally! Given a sorted linked list, we need to convert it into a height-balanced BST 🌳 🧠 Key Idea: The middle element of the list becomes the root. Left half forms the left subtree, right half forms the right subtree. Use slow–fast pointers to find the middle efficiently. 📈 Complexity: Time: O(n log n) Space: O(log n) (recursion stack) 💬 Learning: Balance matters — in trees, in code, and in life 🌿 Sometimes, the middle point creates the strongest foundation. #LeetCode #DSA #BinarySearchTree #LinkedList #CodingChallenge #Python #Algorithm #LeetCodeDaily #100DaysOfCode
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟵 𝗼𝗳 #𝟭𝟴𝟬𝗗𝗮𝘆𝘀𝗢𝗳𝗖𝗼𝗱𝗲 Today, I built on the first/last occurrence solution to 𝗰𝗼𝘂𝗻𝘁 𝗼𝗰𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝗲𝘀 𝗼𝗳 𝗮 𝘁𝗮𝗿𝗴𝗲𝘁 𝗶𝗻 𝗮 𝘀𝗼𝗿𝘁𝗲𝗱 𝗮𝗿𝗿𝗮𝘆 𝘄𝗶𝘁𝗵 𝗱𝘂𝗽𝗹𝗶𝗰𝗮𝘁𝗲𝘀. Using the same lower_bound and upper_bound helpers: Lower bound → first index where element ≥ target Upper bound → first index where element > target The count is simply: count = upper_bound - lower_bound This gives an O(log n) solution — much faster than scanning the entire array, especially with many duplicates. It’s a great example of how breaking a problem into reusable pieces leads to clean and efficient code. Perfect for analytics, frequency analysis, and search optimizations! 📊 #Python #Algorithms #BinarySearch #FrequencyCount #Coding #ProblemSolving
To view or add a comment, sign in
-
-
Day 3 of #100DaysOfLeetCode Problem: 167. Two Sum II – Input Array Is Sorted Category: Arrays / Two Pointers Today’s challenge was all about finding two numbers in a sorted array that add up to a given target. Since the array is already sorted, using two pointers gives an elegant O(n) solution — no need for extra space! 🧠 Key Learnings: Initialized pointers at both ends (l = 0, r = n-1). If the sum is smaller than the target → move left pointer rightward. If the sum is greater → move right pointer leftward. Found the exact indices in linear time using smart pointer movement. 💡Time Complexity: O(n) 💡 Space Complexity: O(1) 🎯 Takeaway: When the array is sorted, two pointers can replace complex hash-based logic, simplifying both time and space usage. Staying consistent and learning one problem at a time! 💪 #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Arrays #TwoPointers #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
How do we simplify complex data without losing key information? That’s the power of Principal Component Analysis (PCA)... a foundational technique in data science for dimensionality reduction and pattern discovery. I built PCA from scratch in Python to show exactly how it works, step by step, with visuals and image compression examples. 👉 Explore the full tutorial on Kaggle: https://lnkd.in/drs9tbFu If you find it useful, don’t forget to upvote, comment your thoughts, and share your feedback! #DataScience #MachineLearning #PCA #Python #Kaggle #DimensionalityReduction
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