Day 65: The "One-Liner" Win 🎯 Problem 1784: Check if Binary String Has at Most One Segment of Ones Today was a lesson in simplifying logic. The challenge: check if a binary string contains more than one contiguous segment of '1's, given that the string starts with '1'. The Strategy: • Observation: If there are multiple segments of '1's, they must be separated by at least one '0'. • The Pattern: In a string starting with '1', any "new" segment of ones would look like "01" somewhere in the string. • The Execution: A simple !s.contains("01") handles the entire check. Sometimes we hunt for complex algorithms when a single string method is the ultimate counter. Clean, readable, and passed all test cases. 🚀 #LeetCode #Java #StringManipulation #Coding #Efficiency #DailyCode
Check Binary String for One Segment of Ones
More Relevant Posts
-
Day 33 of Daily DSA 🚀 Solved LeetCode 58: Length of Last Word ✅ Problem: Given a string s, return the length of the last word (a sequence of non-space characters). Approach: First, trim() the string to remove trailing spaces Traverse the string from the end Count characters until a space is encountered 💡 Key Insight: Instead of splitting the string (which uses extra space), we can simply iterate backwards for an efficient solution. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.17 MB A simple yet important problem to strengthen string traversal techniques. #DSA #LeetCode #Java #Strings #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 LeetCode Problem || Count Submatrices With Equal Frequency of X and Y(3212) Today I worked on a problem where we need to count submatrices based on a condition involving characters in a grid. 🧩 Problem Idea We are given a grid containing: 'X' → treated as +1 'Y' → treated as -1 '.' → treated as 0 We need to count submatrices where: ✔ The total sum is 0 ✔ And at least one 'X' is present #Java #DSA #LeetCode #Matrix #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 39 of Daily DSA 🚀 Solved LeetCode 1446: Consecutive Characters ✅ Problem: The power of a string is the maximum length of a non-empty substring that contains only one unique character. Given a string s, return its power. Rules: * Substring must be non-empty * Substring must contain only one unique character * Return the maximum such length Approach: Used a simple linear scan to track the current streak of consecutive identical characters and update the maximum. Steps: 1. Initialize max and count both to 1 2. Iterate from index 1 onwards 3. If current character equals previous → increment count 4. Else → reset count to 1 5. Update max at every step 6. Return max ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 29 ms (Beats 2.02%) • Memory: 45.33 MB Sometimes the simplest sliding window — just two variables — is all you need to solve a problem cleanly. #DSA #LeetCode #Java #SlidingWindow #Strings #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 81/100 – LeetCode Challenge ✅ Problem: #11 Container With Most Water Difficulty: Medium Language: Java Approach: Two Pointers (Greedy Shrinking) Time Complexity: O(n) Space Complexity: O(1) Key Insight: Area = min(height[i], height[j]) × (j - i) Start with widest container (i=0, j=n-1). Move the pointer with smaller height inward — only this can potentially increase area. Solution Brief: Initialized two pointers at both ends. While i < j: Compute current area using smaller height Update max if current area larger Move the pointer with smaller height inward #LeetCode #Day81 #100DaysOfCode #TwoPointers #Java #Algorithm #CodingChallenge #ProblemSolving #ContainerWithMostWater #MediumProblem #Greedy #Array #DSA
To view or add a comment, sign in
-
-
Day 31/100 - LEETCODE Challenge ✅ Problem : Find First and Last Position of Element in Sorted Array Solved the Search for First and Last Position of Element in Sorted Array problem using an optimized Binary Search approach in Java. Instead of using a linear scan, I implemented two separate binary searches to efficiently find the first and last occurrence of the target element in O(log n) time complexity. This solution improves performance for large datasets and achieved 0 ms runtime (100% beats) on LeetCode. Problems like this help strengthen understanding of binary search variations and edge case handling in sorted arrays. #100DaysOfCode #java #Coding #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
Day 38 of Daily DSA 🚀 Solved LeetCode 1897: Redistribute Characters to Make All Strings Equal ✅ Problem: Given an array of strings, determine if you can make every string equal by moving any character from one string to any position in another string. Rules: * You can pick two distinct indices i and j and move any character from words[i] to any position in words[j] * Any number of operations are allowed * Return true if all strings can be made equal, false otherwise Approach: Used a HashMap to count the total frequency of every character across all strings. If every character's count is divisible by the number of strings, equal redistribution is possible. Steps: 1. Concatenate all strings into one using StringBuilder 2. Count the frequency of each character using a HashMap 3. For every character count, check if it is divisible by the number of words 4. If any count is not divisible → return false 5. Otherwise → return true ⏱ Complexity: • Time: O(n * m) — n = number of words, m = average word length • Space: O(1) — at most 26 characters in the map 📊 LeetCode Stats: • Runtime: 12 ms (Beats 17.93%) • Memory: 46.63 MB A brilliant insight — redistribution is just a divisibility check! No complex simulation needed. #DSA #LeetCode #Java #HashMap #Strings #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 14/100 – #100DaysOfCode Challenge 🔍 Problem Solved: Single Number (LeetCode 136) Today’s problem was about finding the element that appears only once in an array where every other element appears twice. 💡 Key Insight: Used the power of XOR (^) bit manipulation Same numbers cancel out → a ^ a = 0 XOR with 0 gives the number → a ^ 0 = a 👉 By XOR-ing all elements, duplicates vanish, leaving the unique number! ⚡ Approach: Traverse the array once Apply XOR on each element Result = single number ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔥 What I Learned: Bit manipulation can simplify problems drastically XOR is super powerful for pairing problems #Day14 #CodingChallenge #Java #DataStructures #Algorithms #BitManipulation #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Tackling algorithmic challenges one substring at a time! Just solved the “Number of Substrings Containing All Three Characters” problem in Java using a sliding window approach. ✨ Key takeaway: Efficient solutions often come from thinking in terms of windows and counts rather than brute force. 💻 Output validated with test cases — clean, optimized, and accepted! #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #LeetCode #ProgrammingJourney
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
-
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