#day334 of #1001daysofcode problem statement (1009): Complement of Base 10 Integer 💡 Approach: To find the complement of a number, I converted it into binary and flipped every bit (0 → 1 and 1 → 0). After flipping the bits, the resulting binary string was converted back to decimal. Example: 5 → Binary: 101 Complement: 010 → 2 ⏱ Time Complexity: O(log n) 🧠 Space Complexity: O(log n) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
Complement of Base 10 Integer in Java
More Relevant Posts
-
Day 60 - Remove Duplicates from Sorted List Worked on removing duplicate elements from a sorted linked list. Approach: • Traverse the list once • Compare current node with next node • Skip duplicate nodes by adjusting pointers Time Complexity: O(n) Space Complexity: O(1) #Day60 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
To view or add a comment, sign in
-
-
Day 66 — LeetCode Progress (Java) Problem: Find the Difference of Two Arrays Required: Given two integer arrays, return: Elements present in nums1 but not in nums2 Elements present in nums2 but not in nums1 Idea: Use sets to remove duplicates and quickly check membership. Approach: Convert both arrays into sets Iterate over nums1 set: Add elements not present in nums2 set to result1 Iterate over nums2 set: Add elements not present in nums1 set to result2 Return both lists Time Complexity: O(n + m) Space Complexity: O(n + m) #LeetCode #DSA #Java #HashSet #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 59 - Merge Two Sorted Lists Worked on merging two sorted linked lists into one sorted list. Approach: • Used a dummy node to simplify pointer handling • Compared nodes from both lists and attached the smaller one • Appended remaining elements after traversal A classic linked list problem that strengthens pointer manipulation skills. Time Complexity: O(n + m) Space Complexity: O(1) #Day59 #LeetCode #Java #LinkedList #CodingPractice #DSA #TechJourney
To view or add a comment, sign in
-
-
Day: 78/365 📌 LeetCode POTD: Equal Sum Grid Partition I Medium Key takeaways/Learnings from this problem: 1. This problem highlights how prefix sums make grid partitioning super efficient instead of recalculating sums again and again. 2. The key is trying splits smartly (row-wise or column-wise) and checking if both parts can balance out. 3. It’s a good reminder that many 2D problems become easier when you reduce them to 1D cumulative sums. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
🚀𝐃𝐚𝐲 88/100 – 𝐀𝐝𝐝 𝐁𝐢𝐧𝐚𝐫𝐲 Today’s problem was Add Binary — a great exercise to understand how addition works at the binary level. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Just like decimal addition, binary addition also uses a carry, but with base 2. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings from right to left Add digits along with carry Append result and update carry 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? Binary addition rules: 0 + 0 = 0 1 + 0 = 1 1 + 1 = 0 (carry 1) ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Use two pointers (end of both strings) Add digits + carry Append (sum % 2) Update carry (sum / 2) Reverse the result ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐦𝐚𝐱(𝐧, 𝐦)) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) #Day88 #100DaysOfCode #Java #DSA #LeetCode #Strings #CodingJourney
To view or add a comment, sign in
-
-
🧠 Day 30 / 100 – DSA Practice Solved Remove Duplicates from Sorted List on LeetCode 🔗✅ 🔹 Problem Insight: Given a sorted linked list, remove duplicates so each element appears only once. 🔹 Approach: Used a single pointer traversal: Compared current node with next node Skipped duplicate nodes by updating links Leveraged the fact that the list is already sorted 🔹 Complexity: Time → O(n) Space → O(1) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Consistency builds confidence 💪🚀 #Day30 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 65 — LeetCode Progress (Java) Problem: Find All Numbers Disappeared in an Array Required: Given an array of size n containing numbers in the range [1, n], return all the numbers that are missing from the array. Idea: Compare the expected range [1…n] with the actual elements to identify missing values. Approach: Initialize a set containing all numbers from 1 to n. Traverse the array: Remove each element from the set The remaining elements in the set are the missing numbers. Time Complexity: O(n) Space Complexity: O(n) #LeetCode #DSA #Java #HashSet #Arrays #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 31/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 69. Sqrt(x) Used the Binary Search approach to find the integer square root without using built-in power functions. The search space is reduced by checking mid * mid against x. ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) Strengthening problem-solving skills with binary search patterns on answer space. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 48/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 1534. Count Good Triplets Used a brute-force triple nested loop to check all possible triplets and validate the given conditions using absolute differences. ⏱️ Time Complexity: O(n³) 📦 Space Complexity: O(1) Strengthening understanding of nested loop patterns and condition-based filtering. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
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