🚀 Day 523 of #750DaysOfCode 🚀 📌 Problem Solved: Check if Binary String Has at Most One Segment of Ones (LeetCode 1784) 🔎 Problem Summary: Given a binary string s (without leading zeros), we need to check whether the string contains at most one contiguous segment of 1s. If the 1s appear in more than one separate segment, we return false. (LeetCode) 💡 Key Insight: Since the string starts with 1, the only valid structure is: 111...000... If we ever encounter the pattern "01", it means a 1 appeared again after a 0, which creates multiple segments of ones. (AlgoMonster) ⚙️ Approach: Traverse the string or simply check if "01" exists. If "01" is found → more than one segment → return false. ⏱ Complexity: Time: O(n) Space: O(1) 📚 Takeaway: Sometimes string problems become much easier when we identify patterns instead of counting segments. Consistency > Motivation. On to Day 524 tomorrow. 💪 #LeetCode #Java #DataStructures #Algorithms #CodingChallenge #Consistency #ProblemSolving #100DaysOfCode #750DaysOfCode
Check Binary String for At Most One Segment of Ones (LeetCode 1784)
More Relevant Posts
-
🚀 Day 546 of #750DaysOfCode🚀 🔥 Solved: Check if Strings Can be Made Equal With Operations I (LeetCode Easy) 💡 Problem Insight We are allowed to swap characters at indices where: 👉 j - i = 2 This means: Index 0 ↔ 2 (even positions) Index 1 ↔ 3 (odd positions) 🚫 But we cannot mix even and odd indices 🧠 Key Observation The string is divided into 2 independent groups: Even indices → (0, 2) Odd indices → (1, 3) 👉 We can rearrange within each group freely 👉 So both groups must match between s1 and s2 ⚡ Approach Extract characters: Even indices from both strings Odd indices from both strings Sort both groups Compare: Even parts must match Odd parts must match 📈 Complexity Time: O(1) Space: O(1) 💬 Key Takeaway Sometimes problems look like string manipulation, but the real trick is: 👉 Understanding constraints → grouping → independent transformations 🔁 Consistency check ✔️ Another day, another step forward 🚀 #LeetCode #DataStructures #Algorithms #Java #CodingChallenge #ProblemSolving #100DaysOfCode #Consistency
To view or add a comment, sign in
-
-
🚀 Day 3/100 – LeetCode Challenge 🔍 Problem: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be inserted to maintain the sorted order. 💡 Key Concepts Used: • Binary Search • Time Complexity Optimization – O(log n) • Efficient searching in sorted arrays 📚 What I Learned: • How binary search reduces search time significantly compared to linear search • Handling edge cases when the target element is not present • Determining the correct insertion index while maintaining sorted order hashtag #100DaysOfCode #LeetCode #Java #DataStructures #Algorithms #BinarySearch #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 3 of my #30DayCodeChallenge: Handling "Infinite" Numbers! The Problem: Multiply Strings. The Logic: I went back to the basics-literally back to grade school. Since I couldn't rely on the * operator for these massive strings, I simulated the Long Multiplication algorithm: Digit-by-Digit: I broke the strings down, converted characters to integers, and multiplied them one by one. The Index Secret: The product of digits at positions i and j always lands at index (i+j+1). The Carry Phase: I handled the carries in a separate pass to keep the code clean and readable ensuring every digit remains between O and 9. Optimization Highlight: Using a StringBuilder for the final conversion instead of simple String concatenation. This avoids creating multiple immutable String objects in memory, keeping the time complexity at O(m x n). Small steps every day lead to big results. Onward to Day 4! #Java #CodingChallenge #ProblemSolving #Algorithms #StringManipulation #SoftwareDevelopment #150DaysOfCode
To view or add a comment, sign in
-
-
#Day67 of my second #100DaysOfCode Today’s problem pushed me to think carefully about comparisons and sorting logic. DSA • Solved Reverse Pairs (LeetCode 493) — count pairs (i, j) such that i < j and nums[i] > 2 * nums[j] • Brute force: check every pair using nested loops → O(n²) time • Optimal approach: Modified Merge Sort to count valid pairs during merge → O(2n log n) time, O(n) space • Key insight: count pairs across the left and right halves before merging. Another reminder of how divide-and-conquer + merge sort patterns appear in many hard problems. #DSA #Algorithms #LeetCode #MergeSort #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
🚀100 Days of Code Day-26 LeetCode Practice – Remove Duplicates from Sorted Array Solved a classic problem using the Two Pointer Technique 💡 📌 Problem: Given a sorted array, remove duplicates in-place and return the number of unique elements. 🔍 Key Idea: Since the array is sorted, duplicates are adjacent. Using two pointers helps efficiently overwrite duplicates without extra space. ⚡ Complexity: Time → O(n) Space → O(1) 💻 Clean and optimized approach makes this problem a great example of in-place array manipulation! #LeetCode #Java #DataStructures #CodingPractice #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 78 / 100 – LeetCode Daily Challenge 🧠 Problem: Triconic Subarray Maximum Sum 📅 Date: March 7, 2026 🏆 Runtime: 3 ms | Beats 99.94% 📦 Memory: 95.28 MB | Beats 46.16% 📝 Problem Insight Today’s challenge was to find the maximum sum of a triconic subarray – a sequence that first decreases, then increases, and finally decreases again. It’s like a "mountain" with two peaks and one valley in between, but in a specific order: down → up → down. This is a more complex variant of the classic mountain or bitonic subarray problems. It requires careful scanning of the array to detect valid triconic patterns and compute their sums efficiently. 💡 My Approach I used a two-pointer expansion method: Iterate through the array and treat each index as a potential peak or valley. Expand left and right while the pattern matches the triconic property. Keep track of the maximum sum encountered. Although the code snippet is incomplete here, the full solution involves: Precomputing left and right decreasing/increasing trends. Validating the three-phase pattern for each possible center. Avoiding redundant computations to keep the time complexity close to O(n). 📊 Results ✅ 861 / 861 test cases passed ⚡ Runtime: 3 ms (beats 99.94% of Java submissions) 📈 Memory: 95.28 MB (beats 46.16%) 🧠 Key Takeaway Pattern recognition problems like this one are great for sharpening your array traversal logic and understanding how to break down complex patterns into manageable checks. The challenge is not just in finding the sum, but in ensuring the pattern holds throughout. 🔗 Let’s Connect! I’m documenting my #100DaysOfCode journey every day – follow along for more problem-solving insights, optimizations, and LeetCode grind! 💻⚡ #LeetCode #Java #CodingChallenge #100DaysOfCode #Day78 #TriconicArray #ProblemSolving #TechJourney #SoftwareEngineering #Algorithms #DataStructures #CodeNewbie #DevCommunity #Programming
To view or add a comment, sign in
-
-
🚀 Day 55/100: LeetCode Challenge – Path Sum (Binary Trees) Halfway through the 100-day journey and the momentum is only building! Today’s focus was on Binary Trees and recursion with the "Path Sum" problem. 💡 The Logic The goal is to determine if a tree has a root-to-leaf path that sums up to a specific targetSum. My approach used a recursive Depth-First Search (DFS): Base Case: If the node is null, return false. Leaf Check: If we reach a leaf node, check if the remaining sum equals the node's value. Recursion: Subtract the current node's value from the target and move down to the left and right children. 📊 Results Runtime: 0 ms (Beats 100.00% of Java users) ⚡ Memory: 44.74 MB (Beats 89.55% of Java users) 🧠 Recursive solutions for trees always feel like magic when they click. It’s all about breaking down a complex structure into the simplest possible sub-problem. Onward to Day 56! #LeetCode #100DaysOfCode #Java #DataStructures #Algorithms #SoftwareEngineering #BinaryTree #CodingChallenge
To view or add a comment, sign in
-
-
🚀 LeetCode – Subsets | Backtracking Approach Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. 💡 Approach Used – Backtracking I used a recursive backtracking strategy where: 1. Start with an empty subset 2. Add the current subset to the result 3. Choose an element and explore further combinations 4. Backtrack by removing the element to try other possibilities This ensures that we explore all possible combinations systematically. Since each element has two choices (include or exclude), the total subsets become 2ⁿ. #LeetCode #DSA #Backtracking #Java #CodingPractice #Algorithms #ProblemSolving #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 25 of my #100DaysOfCode Journey Today, I solved the LeetCode problem Valid Perfect Square. Problem Insight: Given a positive integer, the task is to determine whether it is a perfect square without using built-in functions like sqrt(). Approach: Used Binary Search to efficiently find whether a number has an integer square root. Initialized search range from 0 to num Calculated mid and checked mid * mid If equal → return true If square is smaller → move right (low = mid + 1) If square is larger → move left (high = mid - 1) Used long for multiplication to avoid overflow issues. Time Complexity: O(log n) — efficient binary search approach Takeaway: Binary Search is not just for arrays — it can be applied to mathematical problems to optimize performance and avoid brute force. #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #BinarySearch
To view or add a comment, sign in
-
-
🚀 Day 8 of #100DaysOfCode Solved LeetCode Problem 69 – Sqrt(x) today using a simple loop approach! 🔍 Problem Summary: Given a non-negative integer "x", return the square root of "x" rounded down to the nearest integer (without using built-in functions). 💡 What I practiced: - Basic iteration using loops - Handling overflow using "long" - Understanding how brute force works before optimizing ⚡ Approach (Brute Force): Start from "i = 0" and keep checking: "i * i <= x" Stop when it exceeds "x", and return "i - 1" 💻 Java Code: public static int mySqrt(int x) { long i = 0; while (i * i <= x) { i++; } return (int)(i - 1); } 📌 Takeaway: Starting with a simple loop helps build clarity. Optimization (like Binary Search) can come next! #LeetCode #Java #100DaysOfCode #CodingJourney #BasicsFirst #ProblemSolving
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