🚀 Day 52 of My Python & DSA Journey Today I revisited Complement of Base 10 Integer on LeetCode — but this time with a more optimized bit manipulation approach! 🔍 Problem Overview: Find the complement of a number by flipping all bits in its binary form. 🧠 Optimized Approach: Instead of converting to binary string, I used bitwise operations: • Create a mask with all bits set to 1 (same length as the number) • Use XOR (^) to flip the bits directly • Special case: when n = 0, return 1 👉 Formula used: (mask - 1) ^ n ⚡ Why this is better: • Avoids string conversion • Works directly on bits (more efficient) • Cleaner and more optimal solution 📊 Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Key Learnings: • Deepened understanding of bitwise operators • Learned how to build bit masks dynamically • Understood difference between basic vs optimized solutions Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day52 #Python #LeetCode #BitManipulation #DataStructures #Algorithms #CodingJourney #100DaysOfCode 🚀
Optimized Bit Manipulation for Complement of Base 10 Integer on LeetCode
More Relevant Posts
-
🗓 7 April 2026 🚀 LeetCode Problem #973 — K Closest Points to Origin Solved this problem using a Heap (Priority Queue) approach in Python. 💡 Approach: - Calculated the distance of each point from origin using: 👉 x² + y² (no need for square root) - Used a max heap (by pushing negative distance) - Maintained heap size = k - If size exceeds k → removed the farthest point ⚡ Time Complexity: O(n log k) ⚡ Space Complexity: O(k) 🔥 This is a great example of optimizing from brute force (sorting O(n log n)) to a more efficient heap-based solution. Consistency update: solving problems daily and improving problem-solving skills step by step. #leetcode #dsa #python #coding #100DaysOfCode #heaps #learning
To view or add a comment, sign in
-
-
🚀 LeetCode Progress Update – Problem Solved! ✅ Problem: Remove Trailing Zeros From a String 💡 Approach: Used reverse traversal to find the first non-zero digit and sliced the string accordingly. 🔍 Key Learning: Efficient string manipulation can avoid unnecessary conversions. Traversing from the end helps solve trailing-based problems quickly. 💻 Code Insight: Instead of removing zeros one by one, I identified the breakpoint and sliced the string — making it optimal and clean. ⏱️ Performance: Runtime: 3 ms ⚡ Beat: 66%+ users Memory: 19.23 MB 📈 Consistency is key — one problem closer to mastery! #LeetCode #CodingJourney #Python #ProblemSolving #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
Day 2 of my LeetCode journey 🚀 Today’s problem: Group Anagrams This challenge was all about grouping strings that share the same characters. I approached it using a dictionary + hashing strategy in Python. For each word, I sorted its characters and used that as a key (converted into a tuple), ensuring all anagrams map to the same bucket. Here’s the core logic I implemented: ▪️Traverse the list of strings ▪️Sort each string → convert to tuple → use as dictionary key ▪️Append original string to the corresponding group ▪️Finally, return all grouped values This approach keeps the implementation clean and scalable. Time Complexity: ▪️Sorting each string takes O(k log k) (where k = length of string) ▪️For n strings → O(n * k log k) overall Space Complexity: ▪️O(n * k) for storing grouped anagrams A solid step forward in understanding how hashing + transformations can simplify complex grouping problems. Staying consistent and leveling up daily 💪 #LeetCode #Day2 #Python #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 61 of My Python & DSA Journey Today I solved LeetCode 2089 — Find Target Indices After Sorting Array, a problem that focuses on counting and understanding sorting behavior efficiently. 🔍 Problem Solved: Given an array and a target value, return the indices of the target after sorting the array in non-decreasing order. 💡 Approach Used: Instead of actually sorting the array, I used an optimized counting approach: • Count numbers less than target • Count numbers equal to target • Generate indices based on these counts This avoids sorting and improves efficiency. ⚡ Key Learnings: • Optimizing without sorting • Counting-based logic • Understanding index positioning after sorting • Writing efficient solutions 📊 Complexity Analysis: ✅ Time Complexity: O(n) Single pass through the array ✅ Space Complexity: O(1) Only storing count variables 🎯 Why This is Efficient? Instead of sorting (O(n log n)), we solved it in linear time O(n). Under the Guidance of: Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day61 #Python #LeetCode #DSA #Algorithms #CodingJourney #100DaysOfCode #10000Coders 🚀
To view or add a comment, sign in
-
-
🚀 Day 7 – LeetCode Journey Today’s problem: String to Integer (atoi) This one really tested my understanding of edge cases and string parsing. Not just coding, but thinking like a machine step-by-step 👇 ✅ Ignored leading whitespaces ✅ Handled positive & negative signs ✅ Extracted numbers until non-digit appears ✅ Managed overflow within 32-bit integer range At first, it looked simple… but the edge cases made it interesting 😅 💡 Key Learning: Writing code is one thing, but handling all possible inputs correctly is what truly matters in real-world problems. Slowly getting better at breaking down problems and building clean logic 💻🔥 On to Day 8… 🚀 #Day7 #LeetCode #CodingJourney #Python #ProblemSolving #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 16 Task – Python Mini Challenge Today’s task was a simple yet powerful exercise to strengthen my looping and conditional logic skills. 🔹 Task: Given a list of numbers, calculate the sum of even and odd numbers separately. 🔹 What I implemented: ✔️ Method 1: Stored even & odd numbers in separate lists and used sum() ✔️ Method 2: Calculated sums directly using variables (more optimized approach) 🔹 Key takeaway: There’s always more than one way to solve a problem. Writing multiple approaches helps in understanding efficiency and clean coding practices. 🔹 What I learned deeply: Using loops effectively Applying conditional logic (if-else) Writing optimized solutions instead of relying only on extra space github link : https://lnkd.in/g4iZcnGt 📌 Completed the task and tested it with different inputs successfully. Building consistency, one problem at a time 💪🚀 #Python #100DaysOfCode #Coding #ProblemSolving #DeveloperJourney #LearnInPublic Codegnan BhanuTeja Garikapati
To view or add a comment, sign in
-
-
🔍 Day 36 of My Problem Solving Journey Today I explored one of the most important concepts in strings — Searching & Finding. In Python, we often use methods like: ✔️ find() → to get the index of a substring ✔️ in → to check existence ✔️ index() → similar to find but throws error if not found But instead of just using built-in functions, I tried to understand the internal logic behind searching 👇 Find the position of a substring without using built-in functions. 🧠 My Approach: Traverse the string Compare characters one by one Return index if match is found Return -1 if not found def my_find(s, sub): for i in r print(my_find("manuuuu", "u")) # Output: 3 ✨ What I learned: How searching works internally Difference between find() and index() Importance of logic building instead of relying on built-ins 📈 Small steps every day = Big growth over time! #Day36 #Python #CodingJourney #ProblemSolving #100DaysOfCode #Learning #Developers #Programming Rudra Sravan kumar
To view or add a comment, sign in
-
-
Another LeetCode problem down! ✅ Today I tackled Valid Anagram. The core of the problem is verifying if two strings contain identical character counts. For my solution, I leveraged Python's built-in sorted() function. The Logic: 1️⃣ Check if the lengths are equal (if not, they can't be anagrams!). 2️⃣ Sort both strings alphabetically. 3️⃣ Compare the sorted strings—if they match perfectly, return True. It’s a clean and readable approach that gets the job done. #Coding #DataStructures #Python3 #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 #Day59 - #geekstreak60 🔹 Problem Solved: Remove Spaces Today’s problem was simple yet important for understanding string manipulation and clean coding practices. 🧩 Problem Statement: Given a string, remove all the spaces and return the modified string while maintaining the order of characters. 💡 Approach: Instead of iterating manually, I used Python’s built-in string method to efficiently remove spaces in one line. 🧠 Key Takeaways: ✔️ Built-in methods can simplify code significantly ✔️ String manipulation is a fundamental skill in DSA ✔️ Always look for optimized and readable solutions ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #DSA #Python #CodingJourney #100DaysOfCode #ProblemSolving #LearningEveryday GeeksforGeeks National Payments Corporation Of India (NPCI)
To view or add a comment, sign in
-
-
Day 1 of my LeetCode journey 🚀 🧩 Problem: Minimum Distance to the Target Element (1848) 💡 Approach: Looped through the array and tracked the minimum absolute difference whenever the target appeared. 📚 What I learned today: • How to iterate through a list efficiently • Using abs() to compute absolute difference • Tracking minimum values during iteration • Initializing variables correctly using infinity • Better understanding of loops and conditional checks in Python 🛠 Language Concepts Used: • for-loop • if condition • abs() function • min() logic / running minimum ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔗 GitHub: https://lnkd.in/gZ23dWkV #LeetCode #Python #DSA #100DaysOfCode #LearningInPublic
To view or add a comment, sign in
-
More from this author
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