✅ Day 69 of 100 Days LeetCode Challenge Problem: 🔹 #1009 – Complement of Base 10 Integer 🔗 https://lnkd.in/geVPugvi Learning Journey: 🔹 Today’s challenge involved finding the bitwise complement of a base-10 integer. 🔹 I first converted the integer into its binary representation using bin(n)[2:] to remove the 0b prefix. 🔹 Then I iterated through each bit and flipped it: • 0 becomes 1 • 1 becomes 0 🔹 After constructing the flipped binary string, I converted it back to a decimal integer using int(s, 2). Concepts Used: 🔹 Binary Representation 🔹 Bit Manipulation 🔹 String Traversal 🔹 Base Conversion (Binary → Decimal) Key Insight: 🔹 Converting the number to binary makes it easy to flip bits directly. 🔹 After inversion, converting the binary string back to base-10 produces the required complement. Complexity: 🔹 Time: O(b) where b is the number of bits in n 🔹 Space: O(b) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
LeetCode Challenge 1009: Complement of Base 10 Integer
More Relevant Posts
-
✅ Day 87 of 100 Days LeetCode Challenge Problem: 🔹 #2840 – Check if Strings Can be Made Equal With Operations II 🔗 https://lnkd.in/gY73RBb5 Learning Journey: 🔹 Today’s problem extended the previous one, allowing swaps between indices where the difference is even. 🔹 I observed that this again partitions the string into two independent groups: • Even indices (0, 2, 4, …) • Odd indices (1, 3, 5, …) 🔹 I extracted characters from even and odd positions separately for both strings. 🔹 Then, I sorted these groups and compared them between s1 and s2. 🔹 If both even-index groups and odd-index groups match, the strings can be made equal. Concepts Used: 🔹 String Manipulation 🔹 Index Grouping (Parity-based) 🔹 Sorting 🔹 Greedy Observation Key Insight: 🔹 Since swaps are allowed only between indices with even distance, characters can only move within their parity group. 🔹 Therefore, the problem reduces to checking if both parity groups have identical character distributions. Complexity: 🔹 Time: O(n log n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 74 of 100 Days LeetCode Challenge Problem: 🔹 #653 – Two Sum IV: Input is a BST 🔗 https://lnkd.in/g9vDFKMA Learning Journey: 🔹 Today’s problem required checking whether there exist two nodes in a Binary Search Tree whose values sum to k. 🔹 I performed a Depth-First Search (DFS) traversal using a stack to visit all nodes of the tree. 🔹 While traversing, I stored each node’s value in a list. 🔹 Then I used a hash set to track visited values and checked whether the complement (k - value) already exists. 🔹 If the complement is found, it means two numbers sum to k, so the function returns True. Concepts Used: 🔹 Depth-First Search (DFS) 🔹 Stack-based Tree Traversal 🔹 Hash Set for Fast Lookup 🔹 Two Sum Pattern Key Insight: 🔹 The classic Two Sum approach works well after collecting values from the BST. 🔹 Using a set allows O(1) lookup, making it efficient to check complements during iteration. Complexity: 🔹 Time: O(n) 🔹 Space: O(n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 75 of 100 Days LeetCode Challenge Problem: 🔹 #415 – Add Strings 🔗 https://lnkd.in/gHVN5VfP Learning Journey: 🔹 Today’s problem required adding two numbers represented as strings without directly using built-in conversion functions. 🔹 I implemented a helper function to convert a string into its numeric value by iterating through digits and multiplying them with the correct powers of 10. 🔹 After converting both strings to integers, I performed the addition. 🔹 Then, I converted the result back into a string by extracting digits using modulo (%) and reversing the constructed list. Concepts Used: 🔹 String to Number Conversion 🔹 Mathematical Digit Handling 🔹 Modulo & Division 🔹 String Construction Key Insight: 🔹 Manually converting between string and integer helps understand how numbers are built and processed internally. 🔹 Constructing the result in reverse and then reversing it ensures correct digit order. Complexity: 🔹 Time: O(n + m) 🔹 Space: O(n + m) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 92 of 100 Days LeetCode Challenge Problem: 🔹 #2011 – Final Value of Variable After Performing Operations 🔗 https://lnkd.in/gX-JQNUJ Learning Journey: 🔹 Today’s problem was about evaluating a sequence of increment and decrement operations. 🔹 I initialized a variable ans = 0 to track the value. 🔹 Used a hashmap to map each operation to its effect: • "++X" and "X++" → +1 • "--X" and "X--" → -1 🔹 Iterated through the operations and updated ans accordingly. 🔹 Returned the final computed value. Concepts Used: 🔹 HashMap / Dictionary 🔹 String Matching 🔹 Simple Simulation Key Insight: 🔹 Instead of using multiple condition checks, mapping operations to values simplifies logic and improves readability. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 78 of 100 Days LeetCode Challenge Problem: 🔹 #3110 – Score of a String 🔗 https://lnkd.in/g9jgxcdK Learning Journey: 🔹 Today’s problem involved calculating the score of a string based on the absolute differences between ASCII values of adjacent characters. 🔹 I iterated through the string starting from index 1 and computed the difference between the current and previous character using ord(). 🔹 For each pair, I added the absolute difference to a running total. 🔹 This approach efficiently accumulates the score in a single pass. Concepts Used: 🔹 String Traversal 🔹 ASCII Value Conversion (ord()) 🔹 Absolute Difference Calculation Key Insight: 🔹 The problem reduces to comparing adjacent elements, making it a straightforward linear scan. 🔹 Using ord() allows direct access to ASCII values, simplifying the computation. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
🚀 LeetCode Win: Missing Number (Beats 100%) Solved this problem using a simple mathematical insight instead of overcomplicating the logic ⚡ 🧠 Core Idea: If a list contains numbers from 0 → n, one number is missing. 👉 So instead of searching for it… I compared: Expected sum (0 → n) Actual sum (given array) ⚙️ Approach: Generate range → 0 to n Compute expected sum Subtract actual array sum ✅ Missing Number = Expected Sum - Actual Sum 🔥 Why this approach stands out: ⏱️ O(n) Time Complexity 💾 O(1) Space Complexity ❌ No extra loops ❌ No sorting ✔️ Clean & efficient 📊 Result: ⚡ Runtime: 0 ms (Beats 100%) 📉 Memory: Optimized 💭 Key Learning: The best solutions aren’t always complex. Sometimes, stepping back and thinking mathematically changes everything. 🚀 Consistency check: Showing up, solving daily, improving 1% 💪 #LeetCode #Algorithms #DataStructures #ProblemSolving #Python #CodingJourney #100DaysOfCode #DeveloperLife #WomenWhoCode #TechGrowth #CodeDaily #ProgrammingLife #SoftwareEngineer #ConsistencyWins
To view or add a comment, sign in
-
-
✅ Day 81 of 100 Days LeetCode Challenge Problem: 🔹 #1897 – Redistribute Characters to Make All Strings Equal 🔗 https://lnkd.in/gZ7wZ7JE Learning Journey: 🔹 Today’s problem required checking if we can redistribute characters so that all strings become identical. 🔹 I combined all strings and used a frequency counter to count occurrences of each character. 🔹 Since we can freely move characters between strings, the only requirement is that each character count must be divisible by the number of strings. 🔹 If any character fails this condition, it’s impossible to evenly distribute it. Concepts Used: 🔹 Hash Map / Frequency Counting (Counter) 🔹 String Concatenation 🔹 Divisibility Check Key Insight: 🔹 The exact arrangement doesn’t matter—only the total frequency distribution matters. 🔹 If every character can be equally divided among all strings, a valid configuration always exists. Complexity: 🔹 Time: O(n * k) (n = number of strings, k = average length) 🔹 Space: O(1) (bounded by alphabet size) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 90 of 100 Days LeetCode Challenge Problem: 🔹 #476 – Number Complement 🔗 https://lnkd.in/gzE6gM7d Learning Journey: 🔹 Today’s problem focused on finding the complement of a number by flipping its binary bits. 🔹 I first converted the integer to its binary representation using bin(num)[2:]. 🔹 Then, I created a helper function to flip each bit: • '0' → '1' • '1' → '0' 🔹 After generating the flipped binary string, I converted it back to an integer using int(..., 2). 🔹 Returned the final complemented value. Concepts Used: 🔹 Binary Representation 🔹 Bit Manipulation 🔹 String Traversal 🔹 Base Conversion Key Insight: 🔹 The complement operation is essentially a bitwise NOT, but only within the significant bits of the number (ignoring leading zeros). 🔹 Converting to binary simplifies the flipping logic for beginners. Complexity: 🔹 Time: O(log n) 🔹 Space: O(log n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 80 of 100 Days LeetCode Challenge Problem: 🔹 #3876 – Construct Uniform Parity Array II 🔗 https://lnkd.in/gENuCXJc Learning Journey: 🔹 Today’s problem focused on determining whether we can construct an array where all elements are either all even or all odd using allowed operations. 🔹 The key observation was around parity (odd/even nature) of numbers. 🔹 Since we can subtract elements, the parity depends on whether differences can produce consistent odd or even values. 🔹 I simplified the logic by checking: • If the minimum element is odd → we can make all elements odd • Otherwise, verify if all elements are already even Concepts Used: 🔹 Parity (Odd/Even Analysis) 🔹 Mathematical Observation 🔹 Greedy Logic Key Insight: 🔹 Subtracting numbers preserves or changes parity in predictable ways. 🔹 The smallest element plays a crucial role in determining whether all elements can be transformed into the same parity. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✅ Day 76 of 100 Days LeetCode Challenge Problem: 🔹 #75 – Sort Colors 🔗 https://lnkd.in/gpH9fEJu Learning Journey: 🔹 Today’s problem required sorting an array containing only 0s, 1s, and 2s (representing colors) in-place without using built-in sort. 🔹 I implemented a selection sort approach, where for each index, I searched for the minimum element in the remaining array. 🔹 Once found, I swapped it with the current position to gradually build the sorted array. 🔹 This ensured the array was sorted in ascending order (0 → 1 → 2). Concepts Used: 🔹 Selection Sort 🔹 In-place Swapping 🔹 Nested Iteration Key Insight: 🔹 Even though the problem has an optimal linear-time solution (Dutch National Flag algorithm), a simple sorting approach like selection sort still works correctly. 🔹 Iteratively placing the smallest remaining element ensures correctness, though not optimal efficiency. Complexity: 🔹 Time: O(n²) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
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