Day 49: Keeping the rhythm with Binary! 🎶 Problem 693: Binary Number with Alternating Bits Today was a smooth one. The challenge: check if a number's binary representation has alternating 0s and 1s with no two adjacent bits being the same. My approach: 1. Converted the integer to a binary string. 2. Ran a linear scan to compare each bit with its neighbor. 3. If any match? Immediate false. It’s a clean O(logN) solution. While there are some "galaxy brain" bitwise tricks to solve this in one line, sometimes a clear string traversal is all you need to keep the streak alive. No nested nightmares today. 🚀 #LeetCode #Java #Binary #CodingChallenge #ProblemSolving #Algorithms
Checking Binary Alternation in Java
More Relevant Posts
-
Day 51: Tackling the "Hard" 🧠 Problem 761: Special Binary String After a streak of "easy"s, the difficulty spiked. This one was essentially a parentheses-balancing problem disguised as binary. The Strategy: • Identify: Tracked "Special" substrings using a balance counter. • Recurse: Processed inner strings recursively to find their best forms. • Sort: Reverse-sorted the resulting components to maximize the value. Ngl, I needed a hand with the implementation, but the logic—treating binary strings like nested structures—finally clicked. Sometimes you have to get cooked to learn. 🧗♂️ #LeetCode #Java #Recursion #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
To view or add a comment, sign in
-
-
#Day54 of my second #100DaysOfCode Today’s problem was all about prefix sums and pattern recognition. DSA • Solved Largest Subarray with Sum 0 (GFG) • Started with brute force by checking all subarrays → O(n²) time • Moved to a better approach using prefix sum • Implemented the optimal solution using HashMap to store first occurrence of prefix sums → O(n) time, O(n) space • Key insight: if the same prefix sum appears twice, the elements in between sum to zero This one really strengthened my understanding of prefix sums and how hashing can reduce quadratic problems to linear time. Slow progress, strong foundations. #DSA #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
-
Day 62: Recursive Patterns 🌀 Problem 1545: Find Kth Bit in Nth Binary String Today was all about string evolution. The task: generate a sequence where each string is formed by taking the previous one, adding a "1", and then appending the reversed and inverted version of the previous string. I took the simulation route for this one. I used a StringBuilder to progressively build the sequence up to N. In each step, I captured the previous state, reversed it, flipped the bits, and glued it all together. It’s a literal implementation of the problem's rules that makes the growth of the string easy to visualize. The brute force simulation worked, but with the string length doubling every iteration (2ⁿ − 1), it definitely tests the limits of heap memory for larger N. It’s a great reminder that while building the whole string is satisfying, there’s usually a hidden recursive logic that can find the answer without storing the entire sequence. We keep moving! 🚀 #LeetCode #Java #StringManipulation #CodingChallenge #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
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 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
💡 Detecting Duplicates using Insertion Sort Logic (No Extra Space!) Instead of using HashSet or extra memory, I tried a different approach — modifying Insertion Sort. 👉 Idea: Assume the left part of the array is already sorted. When inserting the next element (key), we shift bigger elements right. During shifting: If we meet an element equal to the key → Duplicate found immediately If smaller → insert at correct position In simple words: Keep shifting while elements are bigger If equal → duplicate If smaller → insert 📊 Complexity: • Worst Case: O(n²) • Space: O(1) • Early exit if duplicate appears Nice reminder that sometimes classic sorting logic can double as a searching technique! #DSA #Java #Algorithms #ProblemSolving #CodingInterview
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
-
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