🚀 Day 95 of #100DaysOfCode Solved LeetCode #868 – Binary Gap ✅ A clean and elegant bit manipulation problem focused on tracking distances between set bits in a binary representation. Key Takeaways: -> Using bitwise operations (&, >>) for constant-time checks -> Tracking previous set-bit positions efficiently -> Single-pass solution with optimal performance -> Simple logic, strong fundamentals 💡 Language: Java -> Runtime: 0 ms (Beats 100%) ⚡ -> Memory: 42.34 MB Closing in on the finish line — consistency really compounds. 💻🔥 #LeetCode #Java #BitManipulation #Binary #ProblemSolving #100DaysOfCode
Java LeetCode 868 Binary Gap Solution
More Relevant Posts
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfCode 🌱 Topic: Linked List / Recursion ✅ Problem Solved: LeetCode 24 – Swap Nodes in Pairs 🛠 Approach: Used a recursive approach to swap every two adjacent nodes in the linked list. If the list has 0 or 1 node, return it directly (base case). Store the second node (head.next) as a temporary node. Recursively swap the remaining list starting from temp.next. Adjust pointers so the second node becomes the new head of the pair. Connect the swapped pair with the recursively processed list. This swaps nodes without modifying their values, only changing pointers. #100DaysOfCode #Day38 #DSA #LinkedList #Recursion #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Solved LeetCode 868 – Binary Gap using Bit Manipulation. 📌 Problem: Find the longest distance between two adjacent 1’s in the binary representation of a number. Approach: ➡️ Right shift to remove trailing 0’s ➡️ Traverse bit by bit using n & 1 ➡️ Track positions of 1’s ➡️ Update maximum distance dynamically This problem reinforced: ✔ Bitwise operations (&, >>) ✔ Position tracking logic ✔ Thinking in binary instead of decimal Sometimes the cleanest solutions come from understanding bits deeply. Small problems. Strong fundamentals. #Java #DSA #BitManipulation #LeetCode #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 98 of #100DaysOfCode Solved LeetCode #1356 – Sort Integers by The Number of 1 Bits ✅ A clean bit manipulation + sorting problem that rewards thinking beyond plain comparisons. Key Takeaways: -> Using Integer.bitCount() to count set bits efficiently -> Encoding sort priority directly into values for simplicity -> Leveraging built-in sorting for clean and fast solutions -> Small tricks can lead to elegant code ✨ Language: Java -> Runtime: 6 ms (Beats 93.70%) ⚡ -> Memory: 47.42 MB Almost there. Staying consistent till the end 💻🔥 #LeetCode #Java #BitManipulation #Sorting #ProblemSolving #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14/100 – LeetCode Challenge Problem: Linked List Cycle II Today’s problem focused on detecting the node where a cycle begins in a linked list. Approach: Used Floyd’s Cycle Detection Algorithm (Slow & Fast pointers). Move slow by one step and fast by two steps. If they meet, a cycle exists. Reset slow to head. Move both slow and fast one step at a time. The node where they meet again is the starting node of the cycle. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List traversal Floyd’s cycle detection Pointer manipulation #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
#day328 of #1001daysofcode problem statement (1758): Minimum Changes To Make Alternating Binary String An alternating binary string can only follow two patterns: "010101..." or "101010...". I counted the number of changes required to convert the string into both patterns and returned the minimum of the two. ⏱Time Complexity: O(n) 🧠Space Complexity: O(1) Consistency check ✅ One LeetCode problem a day to sharpen problem-solving skills. #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
Day 13/100 – LeetCode Challenge Problem: Linked List Cycle Today’s problem was about detecting whether a cycle exists in a linked list. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare). slow pointer moves one step fast pointer moves two steps If a cycle exists, both pointers will eventually meet If fast reaches null, the list has no cycle Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List traversal Two-pointer technique Cycle detection algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 31/75 — Sum of Two Integers (Without + or -) Today's problem was about performing addition using bit manipulation. Key idea: • XOR (^) gives sum without carry • AND (&) + left shift gives carry Algorithm: while (b != 0): carry = (a & b) << 1 a = a ^ b b = carry Repeat until carry becomes zero. Time Complexity: O(1) Space Complexity: O(1) This problem gave a deeper understanding of how addition works at the binary level. 31/75 🚀 #Day31 #DSA #BitManipulation #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 7/100 – LeetCode Challenge Problem: Palindrome Number Today’s problem focused on number manipulation without converting the integer into a string. Approach: If number is negative → return false Reverse the digits using modulo (% 10) and division (/ 10) Compare reversed number with original number Logic Used: Extract last digit: rem = x % 10 Build reversed number: rev = rev * 10 + rem Remove last digit: x = x / 10 Complexity: Time: O(log₁₀ n) Space: O(1) Key takeaway: Problems involving digits can often be solved mathematically without string conversion. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 42 of #100DaysOfCode 🌱 Topic: Linked List / Two Pointers ✅ Problem Solved: LeetCode 82 – Remove Duplicates from Sorted List II 🛠 Approach: Used a dummy node to simplify handling edge cases where the head might be removed. When two consecutive nodes had the same value, stored that value. Skipped all nodes with that duplicate value using a loop. Linked the previous node to the next distinct node. Continued traversal until reaching the end. This ensures that only unique elements remain in the sorted list. #100DaysOfCode #Day42 #DSA #LinkedList #TwoPointers #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
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