🚀 Day 22 & 23 of #100DaysofCode Bit Manipulation in Java This week, I focused on mastering bitwise operations, which are crucial for competitive programming and low-level optimizations. Here’s what I explored: ✅ Get, Set, Clear, Update ith Bit – Access and modify specific bits in a number. ✅ Clear Range of Bits – Clear bits from 0 to i or i to j efficiently. ✅ Check Power of Two – Using (n & (n-1)) == 0 for fast checks. ✅ Count Set Bits – Count the number of 1s in a number efficiently using Brian Kernighan’s algorithm. 💡 Bit manipulation is not just about numbers; it’s about thinking in binary and optimizing memory and performance.
More Relevant Posts
-
🧩 Day 79 of #100DaysOfCode Today’s problem: LeetCode 3370 – Smallest Number With All Set Bits 💡 The challenge was to find the smallest number greater than or equal to n whose binary representation contains only set bits (1s). 💻 Language: Java ⚙️ Approach: Used bitwise operations to identify numbers whose binary form contains all 1s. The key condition used: (x & (x + 1)) == 0 This ensures that the number has all bits set. ✅ Result: Runtime – 0 ms, beating 100% of Java submissions! ⚡ 📈 Learning: This problem improved my understanding of bit manipulation and binary operations — core concepts for optimizing code performance. #Day79 #LeetCode #100DaysOfCode #CodingChallenge #JavaProgramming #ProblemSolving #BitManipulation #DeveloperJourney #CodeEveryday
To view or add a comment, sign in
-
-
Day 11/100 — Coding Challenge Today’s problem was about identifying leaders in an array, which is a great exercise in understanding traversal from the right and maintaining a dynamic maximum. Problem: Find all elements in an array that are greater than or equal to every element to their right. Approach: Traverse the array from right to left. Keep track of the maximum element encountered so far. If the current element is greater than or equal to this max, it’s a “leader.” Reverse the collected list to maintain left-to-right order. This solution had a time complexity of O(n) and passed all 1111/1111 test cases with 100% accuracy. This challenge reinforced how scanning in reverse can simplify certain problems and eliminate extra computations. #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode #2442 — Count Number of Distinct Integers After Reverse Operations 📘 Problem: You are given an array of positive integers. For each integer, reverse its digits and add it to the array. Finally, return the total count of distinct integers in the resulting array. Example: Input → [1,13,10,12,31] Output → 6 Explanation → After reversing and adding, the array becomes [1,13,10,12,31,1,31,1,21,13]. The distinct numbers are 1, 10, 12, 13, 21, and 31. 🧠 My Approach: I used a HashSet to automatically handle uniqueness. 1️⃣ Loop through each element in the array and add it to the set. 2️⃣ Reverse each number and add the reversed version as well. 3️⃣ Return the final size of the HashSet, which represents the count of distinct integers. 💡 What I Learned: ✅ How HashSet simplifies handling of unique elements ✅ Efficiently reversing numbers using arithmetic instead of strings ✅ Reinforced understanding of loops and data structures working together 💻 Language Used: Java 🔍 Concept: HashSet | Array Manipulation | Number Reversal #LeetCode #Java #DSA #HashSet #CodingUpdate #LearningByDoing #Programming
To view or add a comment, sign in
-
-
🚀 Day 95 of #100DaysOfCode 🧠 Solved "Fibonacci Number" in Java using a space-optimized iterative approach. 🔹 Problem: Given an integer n (0 ≤ n ≤ 30), compute the nth Fibonacci number where F(0)=0, F(1)=1 and F(n)=F(n-1)+F(n-2) for n>1. 🔹 Approach: • Handle base cases (n=0 or n=1). • Use two variables (prev=0, curr=1) and iterate from i=2 to n. • In each step compute next=prev+curr, then update prev=curr and curr=next. • Return curr as the result. 🔹 Key Learning: • Iterative dynamic programming with constant space is ideal when only the last two states are needed. • Avoid using full arrays when you don’t need all historical values. • Clear, readable, and efficient code works well in interviews and production alike. 🔹 Thanks to: • Dr Bharathi Raja N — Director of Training & Placement, Dhanalakshmi College of Engineering • Sreesairam V Sir — Mentor from Aptitude Guru Hem #DhanalakshmiCollegeOfEngineering #LeetCode #Java #100DaysOfCode #Day95 #DynamicProgramming #CodingJourney
To view or add a comment, sign in
-
-
💡 Day 56 of #100DaysOfCode 💡 Today, I tackled LeetCode Problem #2220 – Minimum Bit Flips to Convert Number ⚙️ A bit flip means toggling a binary bit from 0 → 1 or 1 → 0. The goal: find the minimum number of flips needed to convert one integer into another using their binary forms. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 💯% 🚀 📉 Memory: 40.31 MB — Beats 90.20% 🧠 Key Learnings: Refreshed bitwise manipulation concepts. Learned efficient use of XOR (^) to find differing bits. Strengthened understanding of binary representation and counting set bits. 🧩 Approach: 1️⃣ Use XOR (start ^ goal) to identify bits that differ. 2️⃣ Count the number of set bits (1s) — each represents one flip needed. 3️⃣ Return the total count as the minimum flips. ✅ Complexity: Time: O(1) — 32-bit integer fixed loop Space: O(1) ✨ Takeaway: Bitwise problems help sharpen low-level thinking — a must for optimizing performance in system-level or embedded applications. #100DaysOfCode #LeetCode #Java #BitManipulation #CodingChallenge #ProblemSolving #CleanCode #Programming #SoftwareEngineering #TechLearning #Algorithms
To view or add a comment, sign in
-
-
✨ LeetCode 450 – Delete Node in a BST Today I solved an interesting Binary Search Tree problem. 🧩 Problem Summary: We are given a BST and a key. We need to delete the node with that key while ensuring the BST property remains intact. The challenge comes when the node has two children, where we replace it with its inorder successor. 💡 Key Idea: If the node has 0 or 1 child, just replace it directly. If it has 2 children, find the minimum value in the right subtree (inorder successor) and replace the node with it, then delete that successor. 📌 Core Operations Used: Binary Search Tree traversal Inorder successor logic Recursion for subtree restructuring This was a really good practice problem to strengthen my understanding of BST manipulation and tree recursion patterns. #LeetCode #DSA #BinarySearchTree #Java #CodingJourney #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟐𝟏 𝐨𝐟 #50DaysOfDSA 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 : https://lnkd.in/gzNm43Xx 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 : https://lnkd.in/gAXsPq4Q Today’s challenge was all about counting substrings efficiently — without generating them one by one. The problem? Given a binary string, find the number of substrings that contain only ‘1’s, modulo 1e9+7. 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Instead of checking all substrings, simply count consecutive 1s. For every continuous segment of k ones, the number of valid substrings is: 𝐤 * (𝐤 + 𝟏) / 𝟐 But we optimize further by counting while we iterate. 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: -> Maintain a running count of consecutive 1s -> Add that to the total whenever a 1 appears -> Reset when a 0 appears -> Handle large numbers using modulo 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝟏) #leetcode #dsa #java #coding #problemsolving #programming #learningeveryday #devcommunity #softwareengineering #100daysofcode #girlswhocode #problem solving
To view or add a comment, sign in
-
-
💻 DSA – Day 14: Bit Manipulation Today I explored Bit Manipulation, one of the most powerful and efficient techniques in programming. These concepts help solve problems faster using operations directly on binary numbers. 🌈 What I learned today 🔹 💡 Introduction to Bit Manipulation Understanding how numbers are stored in binary and how bitwise operations work at the hardware level. 🔹 🔢 Binary Number System Revisited binary representation — the foundation of all bit operations. ⚙️ Bitwise Operators Covered 🔸 & (Binary AND) 🔸 | (Binary OR) 🔸 ^ (Binary XOR) 🔸 ~ (1’s Complement) 🔸 << (Left Shift) 🔸 >> (Right Shift) Understanding how each operator behaves on bits was the key highlight of today. 🔥 Important Problems I Solved 🔹 🔍 Check if a Number is Odd or Even Using the least significant bit. 🔹 🎯 Get ith Bit Extracting a specific bit from a number. 🔹 ✏️ Set ith Bit Turning a bit on. 🔹 🧹 Clear ith Bit Turning a bit off. 🔹 ♻️ Update ith Bit Combining clear + set for controlled updates. 🔹 🧽 Clear Last i Bits Masking out lower bits for range operations. 🔹 📏 Clear Range of Bits Applying custom masks to clear any segment of bits. 🔹 ⚡ Check if a Number is a Power of 2 A clever O(1) check using n & (n-1). 🔹 🔢 Count Set Bits Counting all 1s in the binary form (Brian Kernighan Algorithm). 🔹 🚀 Fast Exponentiation (Binary Exponentiation) A powerful technique that reduces exponentiation to O(log n) using bit logic. 🚀 Bit Manipulation = Speed + Optimization These are low-level concepts but extremely powerful, especially in competitive programming and interview questions. More exciting DSA concepts coming up next! #DSA #Day14 #BitManipulation #Java #Binary #100DaysOfCode #CodingJourney #LearningInPublic #ProblemSolving
To view or add a comment, sign in
-
💻 From identifying a gap to getting merged! I noticed the JugglerSequence algorithm in TheAlgorithms/Java repository had zero test coverage. So I took action: 1️⃣ Created JugglerSequenceTest.java with 4 comprehensive test cases 2️⃣ Covered edge cases (n=1) and typical inputs (n=2, 3, 9) 3️⃣ Ensured all tests verify correct sequence generation 4️⃣ Got reviewed and merged! ✅ The result? Better code quality for 59k+ stars worth of developers using this repository. Every bug caught in testing is one less bug in production. That's the power of good test coverage! 🎯 What's your first open source contribution story? Drop it in the comments! 👇 Dr. Sripath Roy Koganti #SoftwareTesting #OpenSource #Java #kl #CodingJourney #GitHub #Programming #TestDrivenDevelopment #DeveloperCommunity
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
Woooow 🥰 Congratulations 🎉👏