🔥 Day 148/360 – Learning Something New Today 🚀 This looks tricky at first… but it’s actually very simple 👀 Let’s break it down 👇 📌 Topic: Bit Manipulation 🧩 Problem: Reverse Bits 📝 Problem Statement: Reverse all 32 bits of a given integer 🔍 Example: Input: 43261596 Output: 964176192 💡 Approach: Bit Manipulation (Bitwise Operators) ✔ Step 1 – Extract last bit using (n & 1) ✔ Step 2 – Shift result left and add bit ✔ Step 3 – Shift input right and repeat 32 times ⚡ Key Idea: Build the reversed number bit by bit by shifting and appending the least significant bit ⏱ Complexity: Time → O(1) Space → O(1) #DSA #Java #Coding #ProblemSolving #InterviewPrep #LeetCode #TechJourney #148DaysOfCode
Reverse Bits in Java with Bit Manipulation
More Relevant Posts
-
🔥 Day 147/360 – Stop Thinking in Functions… Start Thinking in Bits ⚡ 📌 Topic: Bit Manipulation 🧩 Problem: Power Function (xⁿ) 📝 Problem Statement: Calculate x raised to the power n efficiently 🔍 Example: Input: x = 2, n = 10 Output: 1024 💡 Approach: Binary Exponentiation (Bit-Based Thinking) ✔ Step 1 – Convert power into binary form ✔ Step 2 – Square the base at each step ✔ Step 3 – Multiply only when current bit is 1 ⏱ Complexity: Time → O(log n) Space → O(1) 📚 What I Learned: The biggest optimization comes from changing how you think, not just how you code #Day147 #DSA #Java #Coding #ProblemSolving #InterviewPrep #LeetCode #TechJourney #360DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 10 — Transitioning from Sliding Window to Binary Search Today’s practice was focused on strengthening previously learned sliding window patterns and starting Binary Search fundamentals. Solved/revisited: Longest Repeating Character Replacement Fruit Into Baskets Max Consecutive Ones III Binary Search Search Insert Position 📌 Biggest learning: Sliding Window and Binary Search require completely different ways of thinking. Sliding Window → managing valid ranges dynamically Binary Search → eliminating impossible search space efficiently Also worked on understanding: left/right boundary movement mid calculation insertion position logic Really enjoying the shift from simply implementing patterns to actually understanding why the logic works. #DSA #Java #BinarySearch #SlidingWindow #Consistency #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 19 of #30DaysOfCode Today’s problem: 20. Valid Parentheses 💡 Problem Summary: Check whether a string containing brackets (), {}, [] is valid or not. A valid string must: close brackets in the correct order match the same bracket type 🧠 Approach: Use a stack data structure Push opening brackets into stack When closing bracket appears, check top element If mismatch occurs → invalid ❌ Stack should be empty at the end ✅ ⚡ Key Learning: Stack works perfectly for balanced bracket problems LIFO concept is very important in DSA Small logic mistakes can break matching order 🔥 Progress: Consistency is turning into confidence 💪 #Day19 #LeetCode #Java #DSA #CodingJourney #30DaysOfCode
To view or add a comment, sign in
-
-
Day 19 LeetCode #88 — Merge Sorted Array Most people try to merge from the front. That’s where the bug begins. The real trick is thinking backwards. Since nums1 already has empty space at the end, we can start filling from the back using 3 pointers: i → last valid element in nums1 j → last element in nums2 k → last index of final merged array Whichever value is bigger goes at position k. This avoids shifting elements and keeps the solution: ✅ In-place ✅ O(m + n) time ✅ O(1) space A small problem, but a powerful lesson: Sometimes the cleanest solution comes from reversing the direction of thought. #LeetCode #DSA #Java #TwoPointers #CodingInterview #ProblemSolving #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 12 of #100DaysOfCode 🧠 LeetCode Daily: Rotate Image (Medium) This one looked like a simple matrix problem… but the real challenge was doing it in-place without using extra space 👀 💡 Problem Insight We’re given an n x n matrix (image), and we need to rotate it 90° clockwise. ⚠️ Constraint: We must modify the same matrix — no extra matrix allowed. 🧩 Intuition Instead of thinking about rotation directly, break it into steps: 👉 Step 1: Transpose the matrix (Swap rows with columns) 👉 Step 2: Reverse each row That’s it — the matrix gets rotated! #100DaysOfCode #LeetCode #Java #DSA #Matrix #ProblemSolving #CodingJourney #Placements
To view or add a comment, sign in
-
-
🚀 Day 88/100 Today’s problem was all about logic simplification ���� 💡 Problem: Given an array of strings, we can move characters between strings. The goal is to check if we can make all strings equal. 🧠 Key Insight: Instead of thinking about operations, think globally! 👉 Combine all characters 👉 Check if each character can be evenly distributed across all strings ✅ If every character frequency is divisible by number of strings → TRUE ❌ Otherwise → FALSE 📌 What I Learned: - Always try to simplify the problem - Focus on final state, not operations - Frequency counting is 🔑 in many problems 💻 Approach: - Count frequency of all characters - Check divisibility with number of strings ⏱ Time Complexity: O(N * M) 📦 Space Complexity: O(1) Small problem, but powerful thinking shift 💯 #Day88 #CodingJourney #Java #DSA #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 9 — #100DaysOfLeetCode Today’s problem: Reveal Cards In Increasing Order (LeetCode 950) This problem was a good reminder that simulation problems become much easier when we focus on positions instead of values. 💡 Approach: -> Sorted the deck -> Used a queue to simulate indexes ->Applied the reveal + move-to-bottom process The most interesting part was: queue.offer(queue.poll()) which perfectly simulates moving the top card to the bottom. ⏱️ Complexity: Time: O(n log n) Space: O(n) #LeetCode #100DaysOfLeetCode #DSA #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 48 of DSA | Solved Minimum Common Value Today’s problem was a simple but powerful use of ⚡ Two Pointers on Sorted Arrays 🧩 Problem Solved: ✅ Minimum Common Value 💡 Problem Idea: Given two sorted arrays, Find the smallest integer that appears in both arrays. If no common value exists → return -1. 🧠 Approach Used: ✅ Two Pointers ✅ Sorted Array Traversal ✅ Greedy Comparison 🔹 Start pointers at the beginning of both arrays 🔹 If elements are equal → common value found ✅ 🔹 Move the pointer of the smaller element 🔹 Continue until one array ends 📊 Complexity: ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(1) 🏆 Result: ⚡ Runtime: 2 ms 🔥 Beats 88.98% submissions 🧠 Key Learning Today: Today reinforced an important idea: 👉 “When arrays are sorted, two pointers can often replace extra hashing or nested loops.” This makes solutions cleaner, faster, and memory efficient 🚀 #Day48 #DSA #Java #TwoPointers #LeetCode #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 32 of #LeetCode Challenge Problem: 50. Pow(x, n) Difficulty: Medium 🔍 Approach: Fast Exponentiation (Binary Exponentiation) Instead of multiplying x repeatedly, used an optimized approach: ➡️ If power is even → square the base ➡️ If power is odd → multiply result with base ➡️ Reduce power by half each step Handled negative powers by converting: Also used long to avoid overflow for large values of n 🚀 ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) 💡 Key Learning: Binary Exponentiation drastically improves performance from O(n) → O(log n) 🔥 #Day32 #LeetCode #DSA #Java #BinaryExponentiation #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 52 – #100DaysOfLeetCode Today I solved LeetCode 796 – Rotate String. Problem Overview: Given two strings s and goal, check if s can become goal after performing any number of rotations. Rotation means shifting the first character to the end. Example: "abcde" → "bcdea" → "cdeab" ... Approach – String Trick (Concatenation): 🔹 Key Insight: If goal is a rotation of s, then it must be a substring of s + s. ✔️ First, check if lengths are equal ✔️ Concatenate s + s ✔️ Check if goal exists inside it This avoids manually rotating strings and keeps the solution efficient. Complexity: Time Complexity: O(n) Space Complexity: O(n) Key Learning: This problem showed how a simple observation can replace brute-force logic. Instead of simulating rotations, we transform the problem using string properties. Reflection: Sometimes the best solutions are not complex they just require a shift in perspective. Problems like this remind me to think smarter, not harder. #Day52 #100DaysOfLeetCode #LeetCode796 #RotateString #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-