🚀 Day 60 / 100 – LeetCode Daily Challenge 💻 Problem: Reverse Bits (Bit Manipulation) Today marks Day 60 of my 100-day LeetCode journey, and I tackled the classic Reverse Bitsproblem — a fascinating deep dive into bit-level manipulation and optimization. 🔍 Problem Overview: Given a 32-bit unsigned integer, the task is to reverse its bits. For example, reversing 43261596 (binary: 00000010100101000001111010011100) gives 964176192 (binary: 111001011110000010100101000000). ⚙️ My Approach: I implemented a highly optimized divide and conquer strategy using bit masking and shifting — no loops, no extra memory, just pure bitwise operations. The algorithm swaps bits in stages: first 16-bit halves, then 8-bit chunks, followed by 4-bit, 2-bit, and finally 1-bit swaps. This results in O(1) time complexity and runs in 0 ms, beating 100% of submissions! 📌 Key Insight: Bit manipulation is not just efficient — it’s elegant. By treating the integer as a fixed-width binary string and applying a series of masks and shifts, we can reverse bits in logarithmic steps rather than iterating through all 32 bits. ✅ Result: ✅ Runtime: 0 ms | Beats 100% ✅ Memory: 100% efficient ✅ Test cases passed with flying colors 🧠 Takeaway: This problem reinforced the power of understanding how data is represented at the bit level. Whether you're working on embedded systems, networking protocols, or performance-critical code, bit manipulation is an essential tool in every developer’s toolkit. On to the next challenge! 💪 #LeetCode #100DaysOfCode #CodingChallenge #Java #BitManipulation #ReverseBits #ProblemSolving #Programming #Tech #DeveloperJourney #LearnInPublic #CodeNewbie #SoftwareEngineering #BitwiseOperations #DailyCoding #Algorithms #DataStructures
Aditya Singhal’s Post
More Relevant Posts
-
🚀 #LeetCodePotd 68 — Binary Gap | ⚡ Runtime: 0 ms (100%) | #365DaysOfCode Cracked another clean bitwise problem today: 🔢 Binary Gap This is NOT a counting problem. It’s a position-tracking problem. Instead of converting to a string, we traverse bits directly and: Track the last position of 1 Compute difference when next 1 appears Update max distance That’s it. 📊 Complexity Analysis MetricValueTime ComplexityO(log n)Space ComplexityO(1) Why O(log n)? Because we process each bit once. No string conversion. No extra arrays. No unnecessary memory allocations. 🧠 What This Problem Actually Tests Bitwise operations mastery Invariant tracking Clean state management Avoiding unnecessary string overhead It’s an “Easy” question — but solving it with bit manipulation instead of string conversion shows maturity. 🏆 Submission Result ✔️ 261 / 261 testcases passed ⚡ Runtime: 0 ms (100%) 📦 Memory: 42.42 MB Small problem. Big mindset shift. 🎯 Takeaway Whenever a question says: “distance between occurrences” Think: Store last index Compute difference Update maximum That pattern appears in arrays, strings, and bit problems repeatedly. Consistent daily reps. Compounding bit by bit. Binary today, billionaire mindset tomorrow. 💪 #LeetCode #BinaryGap #DSA #DataStructures #Algorithms #BitManipulation #Java #Coding #Programming #SoftwareEngineer #TechCareers #InterviewPrep #ProblemSolving #CompetitiveProgramming #100DaysOfCode #WomenInTech #Developers #CodingLife #CodeNewbie #ComputerScience #TechCommunity #CodingJourney #FAANGPrep #PlacementPreparation
To view or add a comment, sign in
-
-
⚡ Binary Logic at Scale: 0ms Performance Win! 🚀 I'm excited to share my latest solution for today's LeetCode challenge! I tackled the "Number of Steps to Reduce a Number in Binary Representation to One" and achieved a perfect 0 ms runtime, beating 100.00% of C++ submissions. 💡 The Strategy: Single-Pass Greedy Simulation Instead of performing heavy big-integer arithmetic, I simulated the reduction process by traversing the binary string from right to left (least significant to most significant bit): Handling Odds and Evens: For each bit, I considered the current carry. If the combined value (bit + carry) was 1, it represented an odd number requiring two steps (add 1 and then divide by 2). If it was 0 or 2, it required only one step. Carry Propagation: I maintained a carry variable to manage the "+1" operations across the string, ensuring the entire process remained O(N). Efficiency: This greedy approach avoids unnecessary string manipulations or divisions, resulting in the top-tier 0 ms execution time. 📊 Consistency Milestone: This win adds to my ongoing streak of high-performance solutions across: Bitwise Mastery: Reverse Bits, Alternating Bits, and Binary Gaps (all 0ms). Recursive Structures: 0ms wins in Binary Tree Traversals and Symmetry checks. Advanced Patterns: Custom sorting by bit counts and Segment Trees. Focusing on writing clean, compiler-friendly C++ is making these complex optimizations feel like second nature. 📈 . Check out the full implementation and my daily progress on GitHub: 📂 Repository: https://lnkd.in/gZ2v73xh . . . . #LeetCode #DSA #CPP #BinaryRepresentation #BitManipulation #Algorithms #ProblemSolving #SoftwareEngineering #CleanCode #Efficiency
To view or add a comment, sign in
-
-
𝗗𝗲𝗲𝗽 𝗗𝗶𝘃𝗲 𝗶𝗻𝘁𝗼 𝘁𝗵𝗲 𝘀𝘁𝗮𝘁𝗶𝗰 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗹𝗮𝘀𝘀 𝗶𝗻 𝗖 💡 The 𝙨𝙩𝙖𝙩𝙞𝙘 storage class is one of the most powerful and unique tools because its behavior completely changes depending on where you define it. While other storage classes like 𝘢𝘶𝘵𝘰 or 𝘳𝘦𝘨𝘪𝘴𝘵𝘦𝘳 are straightforward, 𝙨𝙩𝙖𝙩𝙞𝙘 has a "split personality" that manages both memory lifetime and linking visibility. Here is the simple breakdown from this infographic: 🔒 𝟭. 𝘀𝘁𝗮𝘁𝗶𝗰 𝗶𝗻𝘀𝗶𝗱𝗲 𝗮 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 (𝗜𝗻𝘁𝗲𝗿𝗻𝗮𝗹 𝗠𝗲𝗺𝗼𝗿𝘆) 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Internal static storage. 𝗟𝗶𝗳𝗲𝘁𝗶𝗺𝗲: Program-level. It is not destroyed when the function exits. 𝗦𝗰𝗼𝗽𝗲: Function/Block-level. It can only be seen and modified by that specific function. It's a private variable with a perfect memory! 🌐 𝟮. 𝘀𝘁𝗮𝘁𝗶𝗰 𝗼𝘂𝘁𝘀𝗶𝗱𝗲 𝗮 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻 (𝗚𝗹𝗼𝗯𝗮𝗹 𝗙𝗶𝗹𝗲 𝗦𝗰𝗼𝗽𝗲) 𝗦𝘁𝗼𝗿𝗮𝗴𝗲 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Global static storage. 𝗟𝗶𝗳𝗲𝘁𝗶𝗺𝗲: Program-level. Exists for the entire duration of the program. 𝗦𝗰𝗼𝗽𝗲: File-level. It is shared and can be changed by any function within that single .c file, but it is strictly hidden from functions in any other .c file in your project. It's like a family secret—shared with everyone inside the family (file) but hidden from outsiders (other files)! #CProgramming #EmbeddedSystems #Coding #SoftwareEngineering #StorageClass #LinkedInLearning
To view or add a comment, sign in
-
-
#100DaysOfLeetcode journey 🚀 Day 15/100 — Bitwise Navigation & State Tracking! Today’s Problem: 868. Binary Gap 🔹 The Goal: After yesterday’s focus on counting bits, today was about measuring the spatial relationship between them. Given an integer $n$, the task was to find the maximum distance between two consecutive "set bits" (1s) in its binary representation. 🔹 The Insight: Instead of converting the number to a String (which adds $O(N)$ space overhead), I treated the integer as a stream of bits. By using a sliding anchor approach, I could track the position of the last seen 1 and calculate the distance to the current 1 on the fly. 🔹 The Difficulty: The nuance lies in the "consecutive" requirement. You have to ignore the gaps until you've established a starting point. By initializing my lastPosition to -1, I created a "wait-and-see" state that ensures we only start measuring once a valid pair can be formed. ✨ Achievement: Another 0ms (100th percentile) submission! This problem reinforced how powerful bitwise operators like >> (right shift) and & 1 (masking) are for traversing data without needing extra data structures. 🔍 Steps followed: Bitwise Traversal: Iterated through the number using n >>= 1 to inspect each bit from right to left. Distance Calculation: Used a currentPosition counter to track our index and a lastPosition variable to "remember" where the previous 1 was. Max Update: Leveraged Math.max() to capture the largest gap discovered during the single pass. 🔧 Complexity Analysis: Time Complexity: $O(\log N)$. For a 32-bit integer, we perform at most 32 iterations, making this incredibly fast. Space Complexity: $O(1)$. No strings, no arrays—just a few primitive variables. The momentum is real. Moving from "what" bits are there to "where" they are located is sharpening my mental model for bit manipulation. 🛠️ #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #SoftwareEngineer #BitManipulation #Efficiency #Algorithms
To view or add a comment, sign in
-
-
🚀 Project Demo: JSON Refiner – Advanced Edition Our team developed a JSON Refiner tool that helps validate and improve JSON data by refining the structure and formatting it for better readability. 🔹 Features: ✔ JSON validation ✔ Error detection ✔ Clean and structured output This project helped us understand JSON parsing, data processing, and how structured data can be improved for better performance. #JSON #Programming #SoftwareDevelopment #ProjectDemo
To view or add a comment, sign in
-
Day 62/100 of the LeetCode Challenge complete! 🚀 Today’s problem: Checking if a number has alternating bits in binary representation. What seemed like a straightforward bit manipulation problem turned into a lesson in how elegant solutions often emerge from understanding the underlying patterns rather than brute force iteration. The insight? For numbers with alternating bits, when you shift right by one and XOR with the original, you get a sequence of all 1’s. Then it becomes a simple matter of checking if x & (x+1) equals zero. What I love about this solution is how it transforms a linear scan problem into constant time operations. No loops, no conditionals—just pure bit manipulation doing the heavy lifting. ⚡ Runtime: 0ms (beats 100% 🎉) Memory: 42.51 MB This is the beauty of problem-solving—sometimes the most efficient path isn’t about processing faster, but about thinking differently. Bit manipulation reminds me that at the lowest level, computers speak a simple language, and understanding it unlocks incredible optimizations. Every day brings new patterns, new tricks, and new ways of thinking. The journey continues! 💪 #LeetCode #CodingChallenge #Day62 #100DaysOfCode #Java #BitManipulation #ProblemSolving #Algorithms #SoftwareEngineering #TechCommunity #Programming #DevLife #CodeNewbie #Tech #CodingLife
To view or add a comment, sign in
-
-
🚀 Day 180 of #200DaysOfCoding Today I solved “Special Positions in a Binary Matrix” on LeetCode. 🧠 Problem Idea: We are given a binary matrix and need to count positions where the value is 1 and all other elements in the same row and column are 0. Such positions are called special positions. 💡 Approach: Instead of checking the entire row and column every time, we can optimize by: • Counting the number of 1s in each row • Counting the number of 1s in each column • A cell (i, j) is special if: mat[i][j] == 1 rowCount[i] == 1 colCount[j] == 1 This reduces unnecessary checks and keeps the solution efficient. ⏱ Time Complexity: O(m × n) 📦 Space Complexity: O(m + n) 💻 Language Used: C++ Consistency is the real key. Every day of problem solving improves logical thinking and problem-solving ability. Just 20 more days to complete the #200DaysOfCoding challenge! 💪 #leetcode #codingchallenge #programming #cpp #datastructures #algorithms #softwaredevelopment
To view or add a comment, sign in
-
-
The skill that separates average developers from strong ones: Debugging without panic. Instead of changing random code, ask: - Where does the data break? - Is it transport, logic, or storage? - What does the network tab say? - What does the log actually show? Calm debugging is a superpower. What’s the hardest bug you’ve solved recently? #Developers #Debugging #ProgrammingLife #MERN
To view or add a comment, sign in
-
-
Delegates in C# every new business rule meant writing another method that make The codebase grew. Everything looked the same. root of the problem was hardcoding behavior instead of designing for flexibility. Instead of writing ten methods that differ by one condition, you write one method and pass the behavior in from outside. The logic stays clean. The caller decides the rule. Nothing needs to be rewritten for every new case. Code Example: static List<Product> Search( List<Product> products, Func<Product, bool> filter ) => products.Where(filter).ToList(); // Here we put a second param takes a Func Delegation Search(catalog, p => p.Category == "Electronics"); Search(catalog, p => p.Price < 50); Search(catalog, p => p.Stock > 20); Search(catalog, p => p.Category == "Clothing" && p.Price < 100); // we search for products with different signatures with the same block of code Delegation achieve 3 critical points : 1. Eliminating repetition — One method handles every rule. No more cloning methods for every new condition. 2. Protecting core logic — Pass new behavior in, never rewrite what already works. 3. Behavior as a value — A rule becomes something you store, pass, and swap at runtime — not something locked inside a method. #CSharp #DotNet #SoftwareEngineering #CleanCode #Programming #BackendDevelopment
To view or add a comment, sign in
-
-
Delegates in C# every new business rule meant writing another method that make The codebase grew. Everything looked the same. root of the problem was hardcoding behavior instead of designing for flexibility. Instead of writing ten methods that differ by one condition, you write one method and pass the behavior in from outside. The logic stays clean. The caller decides the rule. Nothing needs to be rewritten for every new case. Code Example: static List<Product> Search( List<Product> products, Func<Product, bool> filter ) => products.Where(filter).ToList(); // Here we put a second param takes a Func Delegation Search(catalog, p => p.Category == "Electronics"); Search(catalog, p => p.Price < 50); Search(catalog, p => p.Stock > 20); Search(catalog, p => p.Category == "Clothing" && p.Price < 100); // we search for products with different signatures with the same block of code Delegation achieve 3 critical points : 1. Eliminating repetition — One method handles every rule. No more cloning methods for every new condition. 2. Protecting core logic — Pass new behavior in, never rewrite what already works. 3. Behavior as a value — A rule becomes something you store, pass, and swap at runtime — not something locked inside a method. #CSharp #DotNet #SoftwareEngineering #CleanCode #Programming #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
Aditya Singhal I applied Different Approach: Take Rightmost but of n using bitwise & operator Then left shift Result by 1 Add rightmost bit using bitwise or operator And then leftshift result Do this for 32 times. It was quite simole though. Yeah but I used a loop🫠