DSA Challenge – Day 21 🚀 Continuing my Data Structures & Algorithms journey, today I solved the problem “Check if Binary String Has at Most One Segment of Ones.” 🔎 Problem Summary: Given a binary string s without leading zeros, determine whether it contains at most one contiguous segment of '1's. 💡 Approach: The key observation is that if multiple segments of '1' exist, the string will contain the pattern "01". So, by checking whether the string contains "01", we can easily determine if there is more than one segment of '1'. If "01" is present → multiple segments → return false If "01" is absent → only one segment → return true ⚡ Time Complexity: O(n) 📦 Space Complexity: O(1) 📈 Key Takeaway: Sometimes the most efficient solutions come from identifying simple patterns within the data rather than overcomplicating the logic. Looking forward to solving more problems and strengthening my problem-solving skills every day. #DSA #ProblemSolving #Java #CodingChallenge #SoftwareDevelopment #LearningInPublic
Checking Binary Strings for One Segment of Ones
More Relevant Posts
-
Day 2 — Pattern-Based DSA Practice Continuing to learn and build in public while solving Data Structures & Algorithms pattern by pattern. Today's focus: Binary Search (Advanced Variations) Problems solved: • Floor in Sorted Array — GFG • Ceil in Sorted Array — GFG • First and Last Occurrence — LeetCode • Search in Rotated Sorted Array II — LeetCode • Single Element in a Sorted Array — LeetCode Key learning: Binary Search is not limited to simple searching. It can be extended to solve problems involving boundaries, duplicates, and modified sorted arrays. Each problem required slight changes in logic, but the core idea remained the same — reducing the search space efficiently. Focusing more on understanding patterns and documenting the journey consistently. #DSA #BinarySearch #LearningInPublic #Java #CodingJourney
To view or add a comment, sign in
-
🚀 DSA Journey | Day 4 — Majority Element (LeetCode) Today, I solved the Majority Element problem and focused on improving my approach from a brute force solution to an optimized one. 🔹 🧠 Problem Understanding Given an integer array, the task is to find the element that appears more than ⌊n/2⌋ times. ✔ The problem guarantees that a majority element always exists ✔ Focus is on optimizing the approach efficiently 🔹 ⚙️ Approach 1: Brute Force For each element, I traversed the entire array again to count its frequency If the frequency exceeded n/2, I returned that element ❌ Time Complexity: O(n²) 👉 Works fine but not scalable for large inputs 🔹 ⚡ Approach 2: Optimized (Using HashMap) Stored frequency of elements using a HashMap Identified the element with count greater than n/2 ✔ Time Complexity: O(n) ✔ Space Complexity: O(n) 💡 Significant improvement compared to brute force 🔹 💡 Key Learnings ✔ How to optimize from O(n²) → O(n) ✔ Importance of choosing the right data structure ✔ Better understanding of frequency-based problems #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Day4 #Learning #Algorithms
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 26 Today’s focus: Binary Search fundamentals. Problems solved: • Binary Search (LeetCode 704) • Search a 2D Matrix (LeetCode 74) Concepts used: • Binary Search • Search space reduction • Index mapping in 2D arrays Key takeaway: In Binary Search, the idea is to repeatedly divide the search space in half. By comparing the target with the middle element, we eliminate half of the array each time, achieving O(log n) time complexity. In Search a 2D Matrix, the matrix can be treated as a flattened sorted array. Using index mapping: row = mid / cols col = mid % cols we can apply binary search directly on the matrix without extra space. These problems highlight how binary search is not limited to 1D arrays—it can be extended to structured data with proper transformations. Continuing to strengthen fundamentals and consistency in DSA problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 53 of My DSA Journey Today I solved a problem on searching an element in a rotated sorted array with duplicates. The array is originally sorted but rotated at some pivot. The task is to determine whether a given target value exists in the array. 🔎 My Approach Instead of directly jumping to complex techniques, I used a simple linear search approach: Traverse through the array from start to end. Compare each element with the target value. If a match is found, return true. If the loop finishes without finding the target, return false. 💡 Key Takeaway Sometimes starting with a simple and correct solution is important before optimizing. While more efficient approaches like modified binary search can reduce time complexity, this straightforward method helps clearly understand the problem first. ⏱ Time Complexity: O(n) Every day I’m improving my problem-solving skills in Java and Data Structures & Algorithms step by step. #Day53 #DSA #Java #ProblemSolving #CodingJourney #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA Daily Progress – Building Consistency I’ve been consistently working on Data Structures & Algorithms, focusing on improving problem-solving skills and optimizing my approach. ✅ Recently Practiced Problems: 🔹 Sort Elements by Decreasing Frequency (GFG) 🔹 Sort Elements by Increasing Frequency (GFG) 🔹 Find First and Last Position of Element in Sorted Array (LeetCode) 🔹 Rearrange Array Elements by Sign (LeetCode) 💡 Key Learnings: • Strengthened concepts of frequency-based sorting using HashMap • Revised Binary Search for first & last occurrence problems • Improved understanding of array rearrangement techniques • Realized the importance of revisiting problems for optimal solutions (initial solutions were around O(2n), now focusing on better approaches) 🙌 Taking guidance and learning from Rahul Maheshwari to improve my problem-solving approach. ⚡ Reflection: Practicing DSA daily is helping me think more efficiently and write optimized code. Consistency + Revision + Optimization = Growth 📈 #DSA #LeetCode #GeeksforGeeks #CodingJourney #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
🚀 Day 88 of DSA Problem Solving 💡 Problem Solved: Two Sum II – Input Array Is Sorted 🔍 Problem Idea: Given a sorted array, find two numbers such that they add up to a target. Return their indices (1-based). 🧠 Key Learning: Instead of using HashMap (like in classic Two Sum), we can optimize using the **Two Pointer Approach** because the array is already sorted. ⚡ Concepts Practiced: * Two Pointer Technique * Array Traversal * Greedy Decision Making ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🚀 Approach: * Start with two pointers: one at the beginning and one at the end * If sum is too small → move left pointer forward * If sum is too large → move right pointer backward * If sum matches target → return indices 🔥 Real Journey Behind Solution: Initially, I thought of using HashMap (habit from Two Sum 😅), but then realized the sorted property is a huge advantage. Switching mindset to use **two pointers** made the solution cleaner and more optimal. This problem reminded me: 👉 Always look for constraints like “sorted” — they often unlock better solutions. 📌 Takeaway: Smart observation > brute force #Day88 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #TechGrowth #TwoPointers
To view or add a comment, sign in
-
-
Day 19 of my Data Structures & Algorithms journey. Today’s problem: Same Tree (Binary Tree recursion) on LeetCode. At first glance it looks simple, but it teaches an important idea: Two trees are identical only if both their structure and node values match at every level. Key concept practiced today: Depth-First Search (DFS) with recursion. Step by step the logic becomes: • If both nodes are null → trees match • If one node is null → trees differ • If values differ → trees differ • Otherwise → recursively check left and right subtrees Small problems like these quietly sharpen problem-solving muscles. Consistency > intensity. #LeetCode #DSA #Java #BinaryTree #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 346 – Daily DSA Challenge! 🔥 Problem: ⚡ Total Hamming Distance The Hamming distance between two integers is the number of bit positions where they differ. Given an integer array nums, return the sum of Hamming distances between all pairs. 💡 Key Insight — Count Bits Column-wise Instead of comparing every pair (O(n²)), analyze each bit position independently. For a given bit: Let ones = number of elements with that bit = 1 Let zeros = n - ones Each pair of (1,0) contributes 1 to Hamming distance. Total contribution for that bit: Sum this for all 32 bits. For each bit column we count ones × zeros and add them. ⚡ Algorithm ✅ Iterate through 32 bit positions ✅ Count how many numbers have that bit set ✅ Compute contribution ones × (n − ones) ✅ Add to result ⚙️ Complexity ✅ Time Complexity: O(32 × n) ≈ O(n) ✅ Space Complexity: O(1) 💬 Challenge for you 1️⃣ Why does this approach avoid pairwise comparison? 2️⃣ How would this change for 64-bit numbers? 3️⃣ Can this be extended to compute XOR sum of all pairs? #DSA #Day346 #LeetCode #BitManipulation #HammingDistance #Math #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
Day - 30 Daily DSA Update Solved: Merge Sorted Array (LeetCode) Today’s problem focused on merging two sorted arrays into one sorted array while modifying the first array in-place. Problem: Given two sorted arrays nums1 and nums2, merge them into a single sorted array stored inside nums1. The first array has enough extra space at the end to accommodate elements from the second array. Approach: Instead of merging from the beginning, I used a two-pointer approach starting from the end of both arrays. • One pointer for the last valid element in nums1 • One pointer for the last element in nums2 • One pointer to place the largest element at the end of nums1 By comparing elements from the back, the larger element is placed at the correct position and pointers move backward. This avoids overwriting elements in nums1. Key Learning: Starting from the end can simplify in-place array problems and prevent unnecessary shifting of elements. What this strengthened: • Two pointer technique • In-place array manipulation • Efficient merging logic • Thinking about optimal traversal direction Each problem continues to strengthen my understanding of core data structures and algorithms. #DSA #DataStructures #Algorithms #Java #LeetCode #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
Day #13 / 100 — Data Structures & Algorithms Focused on Binary Search (answer space + edge cases) today. Problems solved: • Koko Eating Bananas • Find the Smallest Divisor Given a Threshold • Single Element in a Sorted Array • First Bad Version Key takeaway: Binary search is not just about finding an element — it’s about searching the answer space efficiently. What improved today: • Better handling of edge conditions • Clear understanding of low/high movement • Recognizing monotonic patterns faster Consistency is slowly converting concepts into instinct. #100DaysOfCode #DSA #LeetCode #Java #BackendDevelopment
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