Day 10 of Daily DSA 🚀 Solved LeetCode 190: Reverse Bits ✅ 🔍 Approach: Worked with the 32-bit representation of the given integer: • Converted the number into a fixed 32-bit binary string • Used a two-pointer technique to reverse the bits • Converted the reversed binary back to an unsigned integer This approach keeps the logic simple while ensuring correctness for signed integers. ⏱ Complexity: • Time: O(32) = O(1) (constant time) • Space: O(32) = O(1) 📊 LeetCode Stats: • Runtime: 9 ms • Memory: 43.46 MB A good reminder that clarity matters more than micro-optimizations when learning bit manipulation. #DSA #LeetCode #Java #BitManipulation #ProblemSolving #DailyCoding #Consistency
Reverse Bits Solution for LeetCode 190
More Relevant Posts
-
🎯 Day 100 of #100DaysOfCode 🔥 What a way to wrap it up! Solved LeetCode #3666 – Minimum Operations to Equalize Binary String ✅ A problem that blends math, parity logic, and careful case analysis—not your usual binary flip question. Key takeaways: -> Count-based optimization over brute force -> Handling even/odd operation patterns smartly -> Early exits = cleaner & faster logic -> Thinking in terms of operations feasibility rather than simulation 🧠 Language: Java -> Runtime: 0 ms (Beats 83.87%) -> Memory: 47.90 MB 100 days. Countless problems. One habit built: consistency 💪 Onward to harder problems and deeper concepts 🚀 #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #Consistency #100DaysChallenge
To view or add a comment, sign in
-
-
Day 11 of Daily DSA 🚀 Solved LeetCode 1800: Maximum Ascending Subarray Sum ✅ 🔍 Approach: Iterated through the array while maintaining the sum of the current strictly increasing subarray. Whenever the sequence breaks, a new subarray sum is started and stored. Finally, the maximum subarray sum is obtained from the stored values. This method clearly separates each ascending subarray and helps in understanding the problem flow. ⏱ Complexity: • Time: O(n) — single traversal + max lookup • Space: O(n) — list used to store subarray sums 📊 LeetCode Stats: • Runtime: 1 ms ⚡ • Memory: 43.30 MB A good learning step before optimizing further to constant space. #DSA #LeetCode #Java #Arrays #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 29 of Daily DSA 🚀 Solved LeetCode 287: Find the Duplicate Number ✅ Problem: Given an array containing n + 1 integers where each number is in the range [1, n], find the duplicate number. Approach: Used the index marking technique. Key Idea: Treat the value as an index Convert the value to absolute (Math.abs) Mark the visited index by making the number negative If we encounter an index that is already negative, that value is the duplicate This allows us to detect duplicates efficiently without extra space. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 4 ms (Beats 91.67%) ⚡ • Memory: 82.75 MB A clever trick that uses the array itself as a visited map. #DSA #LeetCode #Java #ProblemSolving #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 20 of Daily DSA 🚀 Solved LeetCode 179: Largest Number ✅ Approach: Converted all integers to strings and used a custom comparator while sorting. For two numbers a and b, we compare: a + b vs b + a This ensures the order that forms the largest possible number. Edge Case Handled 💡 If the highest element after sorting is "0", then the entire array contains zeros → return "0" instead of "000". ⏱ Complexity: • Time: O(n log n) — sorting with custom comparator • Space: O(n) — string array 📊 LeetCode Stats: • Runtime: 6 ms (Beats 96.21%) ⚡ • Memory: 44.96 MB (Beats 76.86%) Comparator-based problems really sharpen logical thinking 🔥 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Sorting #Consistency
To view or add a comment, sign in
-
-
Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 89/100 – LeetCode Challenge ✅ Problem: #459 Repeated Substring Pattern Difficulty: Easy Language: Java Approach: Substring Division Check Time Complexity: O(n²) worst case Space Complexity: O(n) Key Insight: A string can be formed by repeating its substring if the substring length divides the string length. Check all divisors of length from largest to smallest for efficiency. Solution Brief: Iterated i from l/2 down to 1 (larger substrings first). If l % i == 0, substring length divides string length. Constructed repeated pattern by appending substring m = l/i times. Compared constructed string with original. #LeetCode #Day89 #100DaysOfCode #String #Java #Algorithm #CodingChallenge #ProblemSolving #RepeatedSubstring #EasyProblem #Substring #Pattern #DSA
To view or add a comment, sign in
-
-
Day 62/100 – LeetCode Challenge ✅ Problem: #401 Binary Watch Difficulty: Easy Language: Java Approach: Brute Force with Bit Counting Time Complexity: O(12 × 60) = O(720) → O(1) Space Complexity: O(1) for result storage Key Insight: Binary watch has 4 LEDs for hours (0-11) and 6 LEDs for minutes (0-59). Each possible time combination has a total bit count = hour bits + minute bits. If total bits equals turnedOn, it's a valid time. Solution Brief: Nested loops over all possible hours (0-11) and minutes (0-59). Used Integer.bitCount() to count set bits in hour and minute. Formatted time string with leading zero for minutes when needed. #LeetCode #Day62 #100DaysOfCode #BitManipulation #Java #Algorithm #CodingChallenge #ProblemSolving #BinaryWatch #EasyProblem #BruteForce #TimeFormatting #DSA
To view or add a comment, sign in
-
-
Day 61/100 – LeetCode Challenge ✅ Problem: #190 Reverse Bits Difficulty: Easy Language: Java Approach: Bit Manipulation (LSB to MSB) Time Complexity: O(1) — fixed 32 iterations Space Complexity: O(1) Key Insight: Reverse bits by building result from least significant bit to most significant bit. For each bit position i (0 to 31): Extract i-th bit from original: (n >> i) & 1 Place it at reversed position: left shift result and OR with extracted bit Solution Brief: Loop 32 times (once per bit). Left shift rev to make room for new bit. Extract LSB from n at position i and OR it into rev. Return final reversed integer. #LeetCode #Day61 #100DaysOfCode #BitManipulation #Java #Algorithm #CodingChallenge #ProblemSolving #ReverseBits #EasyProblem #Binary #Bitwise #DSA
To view or add a comment, sign in
-
Explore related topics
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
Bit manipulation would be better approach try it