Solved LeetCode 1009 – Complement of Base 10 Integer today. In simple terms, the problem asks us to flip every bit of a number’s binary representation — change all 0s to 1s and all 1s to 0s — and then convert it back to a decimal number. The key idea was to create a bit mask of all 1s with the same length as the number’s binary form, and then use the XOR (^) operation to flip the bits. A small problem, but a good reminder of how powerful bit manipulation can be in programming. #LeetCode #DSA #Java #CodingJourney #ProblemSolving
Flip Binary Bits to Decimal with XOR
More Relevant Posts
-
🚀 Day 58 — LeetCode Practice 🚀 Today’s problem: Shuffle String (LeetCode 1528) 💡 Key Learning: • Learned how to rearrange characters using index mapping • Understood how placing elements at correct positions simplifies the problem • Practiced writing clean and efficient O(n) solutions • Strengthened thinking for array + string manipulation 🧠 Approach in simple words: Instead of modifying the original string, create a new array and place each character at its correct index using the given indices. ✨ Takeaway: Sometimes the simplest idea — “put the element in its right place” — gives the most optimal solution. Consistency is the real game 💪 #Day58 #LeetCode #DSA #CodingJourney #Java #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Challenge – Day 30 Today I solved LeetCode 1009 – Complement of Base 10 Integer. 📌 Approach: 1️⃣ Convert the number to binary (conceptually). 2️⃣ Flip all bits (0 → 1 and 1 → 0). 3️⃣ Convert the result back to decimal. Instead of actually converting to binary, we create a mask of all 1s having the same length as n and then use XOR. Example: n = 5 → binary 101 Complement → 010 → decimal 2 📈 Complexity Time: O(log n) Space: O(1) Every problem solved strengthens problem-solving skills and understanding of bit manipulation. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #75DaysOfCode
To view or add a comment, sign in
-
100 Days of Coding Challenge – Day 27 📌 Problem: Maximum Average Subarray I 💻 Language: Java 🧠 Concept Used: Sliding Window Technique 🔍 Platform: LeetCode Today’s challenge was to find a contiguous subarray of length k that has the maximum average value. Example: Input: [1,12,-5,-6,50,3], k = 4 Output: 12.75 Approach: ✔ Calculate the sum of the first window of size k ✔ Slide the window by removing the left element and adding the next element ✔ Keep track of the maximum sum ✔ Divide by k to get the maximum average Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/ghU4zrpt 🔗 Code: https://lnkd.in/g7qXeHx6 #100DaysOfCode #Day27 #Java #DSA #LeetCode #SlidingWindow #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 65 #LeetCode Practice ✅ Problem Solved: Minimum Number Game 💡 What I learned today: • Importance of sorting before processing • Understood how to simulate a game step-by-step • Learned swapping elements in pairs efficiently • Improved thinking on pattern-based array problems 📊 Approach: • First, sort the array • Traverse the array in steps of 2 • Swap every pair of elements • Return the modified array 🧠 Key Insight: Sometimes problems look complex, but after sorting, a simple pattern (pair swapping) solves it easily. 🔥 Consistency is the key! Showing up every day is building my problem-solving mindset step by step. #Day65 #LeetCode #DSA #Java #CodingJourney #Consistency #Learning
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 49 Today I solved the Linked List Cycle problem. Problem Insight: Given a linked list, determine whether it contains a cycle (loop). A cycle occurs when a node points back to a previous node instead of reaching null. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare) Maintained two pointers: Slow pointer moves one step at a time Fast pointer moves two steps at a time If a cycle exists, both pointers will eventually meet If not, the fast pointer will reach the end of the list Key Learning: Using two pointers with different speeds helps efficiently detect cycles without extra space. Complexity: Time: O(n) Space: O(1) Understanding pointer movement made this problem much easier to solve. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
Continuing my DSA practice on LeetCode, today I worked on another hard problem. * Problem: Valid Number (65) * Approach: This problem is about validating whether a string represents a valid number, including integers, decimals, and scientific notation. I solved it by scanning the string once and keeping track of certain conditions using flags: seenDigit to check if we have encountered any digit. seenDot to ensure only one decimal point appears. seenE to track if an exponent (e or E) appears. digitAfterE to make sure digits exist after the exponent. While iterating through the string, I handled different cases such as digits, signs (+/-), decimal points, and exponent characters and updated the flags accordingly. * Key Learning: This problem helped me practice carefully handling multiple conditions while parsing strings, which is common in many real-world validation and parsing tasks. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 48 Today I solved the House Robber problem. Problem Insight: Given an array where each element represents money in a house, the goal is to find the maximum amount that can be robbed without robbing two adjacent houses. Approach: At each house, there are two choices: Rob the current house and add its value to the maximum from two houses back Skip the current house and take the maximum till the previous house Used a dynamic programming approach to make this decision efficiently Key Learning: Dynamic Programming becomes easier when we break the problem into small decisions. At each step, we only need to decide whether to pick or skip the current element. Complexity: Time: O(n) Space: O(1) This problem helped me understand how to make optimal decisions using previous results. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🔥 Day 13/100 Days Coding Challenge ✅ Problem Solved: Max Consecutive Ones Today’s problem was about finding the maximum number of consecutive 1’s in a binary array. 💡 Key Idea: Traverse the array, count consecutive 1’s, and reset when encountering 0 — while tracking the maximum count. 🧠 What I Learned: Importance of maintaining a running count Using Math.max() efficiently Solving problems in O(n) time with constant space 💻 Approach: Initialize count = 0, max = 0 Loop through array If element is 1 → increment count Else → reset count Update max at each step Consistency is key 🔑 — small steps every day lead to big results! #Day13 #100DaysOfCode #Java #DSA #CodingChallenge #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 16/100 Days of Code Challenge Solved the classic “Sort Colors” problem (LeetCode 75) today! 🎯 🔹 Problem Summary: Given an array containing 0s, 1s, and 2s (representing colors), sort them in-place without using built-in sort. 🔹 Approach Used: Maintained three pointers: low, mid, high Efficiently partitioned the array in a single pass 🔹 Key Learning: ✔️ In-place sorting can be done in O(n) time ✔️ Using pointers smartly avoids extra space 💡 Time Complexity: O(n) 💡 Space Complexity: O(1) 🔹 Code Highlight : Used swapping and pointer movement to organize elements in one traversal. Consistency is the key 🔑 — one step closer to mastering DSA! #Day16 #100DaysOfCode #DSA #Java #CodingChallenge #LeetCode #ProblemSolving #TechJourney
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