🚀 Day 66 / 100 Days of LeetCode Challenge ✅ Problem Solved: Binary Gap 💡 Goal: Find the longest distance between two consecutive 1s in the binary representation of a given integer. 🧠 Thought Process: Removed trailing zeros to start from the first 1. Handled edge case where number is 1 → return 0. Iterated through bits, tracking gap length between 1s. Updated max gap whenever a 1 was found. 📈 Result: ⚡ Runtime: 0 ms (Beats 100% 🎉) 💾 Memory: 42.56 MB (Beats 14.06%) 📝 Key Takeaway: Efficient bit manipulation can drastically simplify problems involving binary representations. Always consider using bitwise operators for performance gains! #LeetCode #100DaysOfCode #CodingChallenge #Java #BitManipulation #ProblemSolving #TechJourney #DeveloperLife #WomenInTech #CodeNewbie #Programming #DailyCoding #BinaryGap #LearnToCode #DSA #Algorithms
Binary Gap Challenge Solved in Java
More Relevant Posts
-
Day 53 - LeetCode Journey Solved LeetCode 80: Remove Duplicates from Sorted Array II (Medium) using an in-place two-pointer approach. This journey isn’t about solving the hardest problems daily, but about showing up consistently and improving step by step. Problems like this strengthen core fundamentals of arrays and in-place manipulation. Today’s problem reinforced key concepts like: • Using two pointers to track valid positions • Maintaining constraints (at most twice occurrence) • Performing operations in-place with O(1) space • Writing clean and efficient logic The idea is simple — allow each element at most twice by comparing with the element at index i-2, ensuring the array stays valid 💡 Every problem adds a new layer to problem-solving skills, and that’s where real growth happens 💯 ✅ Better understanding of array manipulation ✅ Improved in-place optimization skills ✅ More confidence in DSA concepts Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #Programming #DeveloperJourney #KeepCoding
To view or add a comment, sign in
-
-
Day 57 - LeetCode Journey Solved LeetCode 2104: Sum of Subarray Ranges (Medium) today using a brute force + optimization approach. This journey isn’t about solving the hardest problems daily, but about showing up consistently and improving step by step. Problems like this help in building a deeper understanding of arrays and how subarrays behave. Today’s problem reinforced key concepts like: • Understanding how to generate all subarrays efficiently • Tracking minimum and maximum values dynamically • Avoiding recomputation using smart updates • Writing clean and logical nested loop solutions The idea is simple — for each starting index, expand the subarray and keep updating min and max to calculate the range 💡 Every problem adds a new layer to problem-solving skills, and that’s where real growth happens 💯 ✅ Better understanding of subarrays and ranges ✅ Improved thinking for optimization ✅ More confidence in array-based problems Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #Programming #DeveloperJourney #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 522 of #750DaysOfCode 🚀 Today I solved the LeetCode problem “Minimum Changes To Make Alternating Binary String.” 🔹 Problem: Given a binary string consisting of 0s and 1s, we need to make the string alternating (no two adjacent characters are the same). In one operation, we can flip any character (0 → 1 or 1 → 0). The goal is to find the minimum number of operations required. 🔹 Key Idea: An alternating string can only follow two possible patterns: 1️⃣ 010101... 2️⃣ 101010... So we: Count mismatches assuming the string starts with '0'. The other pattern mismatches will be n - mismatch. The minimum of these two values gives the answer. 🔹 Time Complexity: O(n) – we traverse the string once. 📌 Example Input: "1111" Possible alternating strings → "0101" or "1010" Minimum operations → 2 Problems like this highlight how pattern observation can simplify the solution. #leetcode #programming #coding #java #softwaredevelopment #dsa #problemSolving #750DaysOfCode
To view or add a comment, sign in
-
-
Day 98 of my 100 Days of LeetCode Challenge 🚀 Solved Longest Increasing Subsequence (LIS) — a classic Dynamic Programming + Binary Search problem. The task is to find the length of the longest strictly increasing subsequence in an array. Approach used in my solution (Optimized O(n log n)): • Maintained a list res to store the smallest possible tail value for increasing subsequences of different lengths • If the current number is greater than the last element in res, append it • Otherwise, use binary search to find the correct position and replace the element • The size of res at the end gives the length of LIS Important Insight: The list does not store the actual LIS, but it maintains optimal subsequence tails to guarantee maximum possible length. Time Complexity: O(n log n) Space Complexity: O(n) This problem is a huge milestone in understanding advanced DP optimization techniques. #100DaysOfCode #100DaysOfLeetCode #LeetCode #DynamicProgramming #BinarySearch #LIS #Java #DSA #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 80/100 – LeetCode Daily Challenge 🧠 Problem: Concatenated Binary 📌 Difficulty: Medium Today’s challenge was to concatenate the binary representations of numbers from 1 to n and return the decimal value of the resulting binary string. 💡 Approach: Instead of actually forming the string, I used bit manipulation to simulate the concatenation: For each number i, compute its bit length using floor(log2(i)) + 1. Left shift the current result by that many bits and add i, applying modulo at each step to prevent overflow. This gives an efficient O(n) solution in both time and space. 📊 Result: ✅ 403 / 403 test cases passed ⚡ Runtime: competitive and clean This problem was a great reminder of how bitwise operations can elegantly solve problems that seem string-heavy at first glance. #LeetCode #CodingChallenge #100DaysOfCode #Day80 #Java #BitManipulation #ProblemSolving #Tech #Programming #DailyCoding #DevCommunity #WomenWhoCode #CodeNewbie
To view or add a comment, sign in
-
-
Day 52 - LeetCode Journey Solved LeetCode 11: Container With Most Water (Medium) today using the Two Pointer approach. This journey isn’t about solving the hardest problems daily, but about showing up consistently and improving step by step. Problems like this help in building a deeper understanding of how optimization actually works. Today’s problem reinforced key concepts like: • Using two pointers to reduce time complexity • Understanding how width and height affect area • Moving the pointer with smaller height for better results • Avoiding brute force and thinking optimally The key idea is simple — start from both ends and move intelligently to maximize the area 💡 Every problem adds a new layer to problem-solving skills, and that’s where real growth happens 💯 ✅ Better understanding of two-pointer technique ✅ Improved optimization thinking ✅ More confidence in DSA concepts Still a long way to go, but progress is progress 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #Programming #DeveloperJourney #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 85 of #100DaysOfCode Today I practiced a simple yet useful array prefix minimum problem. 🔹 Problem Given an array cost, return a new array where each element represents the minimum cost encountered from the start up to that index. 🔹 Approach I used a running minimum technique: Maintain a variable min to track the smallest value seen so far. Traverse the array. Update min using Math.min(min, cost[i]). Store the current minimum in the result array. 🔹 Time Complexity ⏱ O(n) – Single pass through the array. 🔹 Space Complexity 📦 O(n) – For storing the result array. 🔹 Key Learning This is a classic prefix computation pattern where we keep track of information while traversing the array. #DSA #Java #Programming #CodingJourney #100DaysOfCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day - 24/100 : 📌 Problem : Binary Number with Alternating Bits 🔗 Problem Link : https://lnkd.in/gCDJXjEK 💡 Approach The goal is to check whether adjacent bits in the binary representation are different (i.e., 101010... pattern). Extract the last bit of the number using n & 1. Right shift the number using n >> 1 to move to the next bit. Again extract the next bit using n & 1. Compare the two bits: If they are equal, the number does not have alternating bits → return false. Continue this process until all bits are checked. If no two adjacent bits are the same, return true. #100DaysOfLeetCode #LeetCode #DSAWithKunal #Algorithms #Java #BitManipulation #CodingPractice #ProblemSolving #DeveloperJourney #Programming
To view or add a comment, sign in
-
-
Friday Learning: A Simple Trick That Saves Time Today I solved LeetCode 3567 — and almost overcomplicated it. At first, I thought: “Compare every pair inside the submatrix” → O(n²) But then I realized something simple 👇 Sort the elements. Once sorted, the minimum absolute difference will ALWAYS be between adjacent values. Approach: • Extract k × k submatrix • Remove duplicates (HashSet) • Sort elements • Check adjacent differences Complexity: O(m × n × k² log k) Lesson: Sometimes the best optimization isn’t a complex data structure… It’s just recognizing the pattern. Building consistency, one problem at a time. - Ishwar Chandra Tiwari | CodeWithIshwar #leetcode #dsa #programming #java #developers #coding #buildinpublic
To view or add a comment, sign in
-
🚀 Day 47 of DSA Problem: Longest Palindromic Substring A palindrome reads the same forward and backward. The challenge was to find the longest such substring inside a given string. 💡 Key Idea: Expand around each character (center) and check both odd and even length palindromes. ⏱ Time Complexity: O(n²) 💾 Space Complexity: O(1) This problem reinforced how choosing the right approach can drastically reduce complexity compared to brute force solutions. Consistent practice is sharpening my problem-solving skills step by step. 💪 #DSA #Java #CodingPractice #LeetCode #Programming #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