🚀 Day 47 of #100DaysOfCode Today’s problem was a clean and clever array-based challenge — 🔢 LeetCode: Single Number 📌 Problem Summary You’re given an array where every element appears twice except one. The task is to find that single unique number. 🧠 My Approach: Sorting + Pattern Check I followed a straightforward and intuitive approach: First, sort the array Traverse elements in steps of 2 If a pair doesn’t match, the unmatched value is the answer If all pairs match, the last element is the single number This works because sorting places duplicate numbers next to each other. ⚙️ Complexity Analysis ⏱ Time: O(n log n) (due to sorting) 💾 Space: O(1) (in-place logic) 💡 Note: This problem can also be optimized to O(n) time & O(1) space using XOR — exploring that next! 🔥 Key Learning Even simple problems can have multiple valid approaches Starting with a clear, readable solution builds strong intuition Optimization is powerful—but clarity comes first ✅ All test cases passed successfully ✔ Consistency > Speed — onward to Day 48 🚀 #100DaysOfCode #LeetCode #Java #Arrays #ProblemSolving #DSA #CodingJourney #Consistency
LeetCode: Single Number Array Challenge
More Relevant Posts
-
🚀 Day 57 of #100DaysOfCode Today’s problem was a clean and classic two-pointer exercise — 🔁 LeetCode 344: Reverse String Simple on the surface, but a great reminder of in-place algorithms and pointer manipulation. 📌 Problem Summary You’re given a character array s. Your task is to reverse the array in-place, using O(1) extra space. 🧠 Approach Used: Two Pointers ✔️ Initialize: left = 0 right = s.length - 1 ✔️ Swap characters while left < right, then move pointers inward. This ensures: No extra memory Linear traversal Clean and readable logic ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (in-place) ✔️ 477 / 477 test cases passed 🚀 Runtime: 0 ms (Beats 100%) 🔥 Key Learning Even the simplest problems reinforce core fundamentals: Two-pointer technique In-place operations Space optimization Mastering basics = dominating harder problems later 💪 Onward to Day 58 🚀 #100DaysOfCode #LeetCode #ReverseString #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 27/100 – 𝐃𝐚𝐲𝐬 of Code Challenge Solved LeetCode #20 – 𝐕𝐚𝐥𝐢𝐝 𝐏𝐚𝐫𝐞𝐧𝐭𝐡𝐞𝐬𝐞𝐬 🔹 Problem:Given a string containing (), {}, and [], determine if the parentheses are valid (correct order & matching types). 🔹 Approach Used: 𝐒𝐭𝐚𝐜𝐤 + 𝐇𝐚𝐬𝐡𝐌𝐚𝐩 Push opening brackets onto the stack On encountering a closing bracket: Check stack is not empty Match it with the correct opening bracket At the end, stack should be empty 🔹 Why Stack? Because it follows 𝐋𝐈𝐅𝐎 (𝐋𝐚𝐬𝐭 𝐈𝐧, 𝐅𝐢𝐫𝐬𝐭 𝐎𝐮𝐭) — perfect for matching nested structures. 🔹 Complexity: 𝐓𝐢𝐦𝐞: 𝐎(𝐧) 𝐒𝐩𝐚𝐜𝐞: 𝐎(𝐧) 🔹 Key Learning: Stack-based problems become very intuitive once you visualize how elements are 𝐩𝐮𝐬𝐡𝐞𝐝 𝐚𝐧𝐝 𝐩𝐨𝐩𝐩𝐞𝐝. #100DaysOfCode #Day27 #LeetCode #DSA #Stack #Java #ProblemSolving #Consistency #CodingJourney
To view or add a comment, sign in
-
-
🚀 Solved LeetCode 338: Counting Bits 🚀 I recently worked on the Counting Bits problem, where the task is: 👉 Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i. 🔹 My Approach: Initialize an array of size n+1. For each number from 1 to n: Copy the number into a temporary variable. Use a loop to repeatedly divide by 2, counting the remainder (num % 2) each time. Store the total count of 1’s in the array. Return the final array. 📊 Complexity Analysis: Time Complexity: O(n log n) Each number requires about log(i) steps to process its binary digits. Space Complexity: O(n) Only the result array of size n+1 is used. ✨ Key Learning: This problem strengthened my understanding of binary representation and iterative problem solving. It was a great reminder that even simple bitwise operations can unlock powerful solutions. #LeetCode #Java #ProblemSolving #BackendDevelopment #CodingJourney #BitManipulation
To view or add a comment, sign in
-
-
🚀 Day 76 of #100DaysOfCode Today I worked on a clean and elegant array manipulation problem — LeetCode: Rotate Array ✅ 📌 Problem Summary Given an array, rotate it to the right by k steps in-place, without using extra space. 🧠 Approach Used: Reverse Technique Instead of shifting elements one by one, I used a smart 3-step reverse strategy: Reverse the entire array Reverse the first k elements Reverse the remaining n − k elements This achieves the rotation efficiently and keeps the solution simple. ⚙️ Complexity ⏱ Time: O(n) 💾 Space: O(1) (in-place) 🔥 Key Learnings Sometimes the best solution is about reordering operations, not adding complexity In-place algorithms are powerful when space constraints matter Reverse logic is a recurring and underrated pattern in array problems Onward to Day 77 🚀 Consistency > Motivation 💪 #100DaysOfCode #LeetCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Grinding 🚀 Today was focused on strengthening Two Pointers mastery and improving problem-solving speed through practice. 🔹 DSA & LeetCode Practice Solved multiple problems by applying the Two Pointers pattern: LeetCode 11 — Container With Most Water Learned how pointer movement helps maximize area efficiently LeetCode 125 — Valid Palindrome Applied two pointers for string validation after preprocessing LeetCode 2824 — Count Pairs Whose Sum is Less than Target Understood how sorted arrays + two pointers help count pairs efficiently LeetCode 26 — Remove Duplicates from Sorted Array Strengthened in-place array manipulation using pointer technique 📌 Key takeaway: The Two Pointers pattern is powerful for: Sorted arrays Pair problems String validation Space-optimized solutions The more I practice patterns, the faster I recognize where to apply them. #DailyGrind #DSA #LeetCode #TwoPointers #ProblemSolving #Java #Consistency #LearningInPublic #InterviewPrep
To view or add a comment, sign in
-
🚀 Day 74 of #100DaysOfCode Today’s challenge was a clean and efficient array problem — LeetCode: Merge Sorted Array ✅ 📌 Problem Summary You’re given two sorted arrays, where the first array has extra space at the end. The task is to merge the second array into the first in-place, keeping everything sorted. 🧠 My Approach Instead of shifting elements forward (which is costly), I used a reverse two-pointer technique: Start comparing elements from the end of both arrays Place the larger element at the last available position Move pointers accordingly until all elements are merged This avoids extra space and keeps the solution optimal. ⚙️ Complexity ⏱ Time: O(m + n) 💾 Space: O(1) (in-place merge) 🔥 Key Learning Working from the back can simplify in-place array problems Two-pointer strategies are incredibly powerful for sorted data Another day, another solid problem solved 💪 Onward to Day 75 🚀 #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 49 of #100DaysOfCode Today’s challenge was a clean and elegant Two Pointer problem — 🔢 LeetCode: Two Sum II – Input Array Is Sorted 📌 Problem Summary You’re given a sorted array of integers and a target value. Your task is to find two numbers such that their sum equals the target and return their 1-based indices. ⚠️ Constraint: The array is already sorted, which opens the door to an optimized approach. 🧠 My Approach: Two Pointers Instead of using a HashMap, I leveraged the sorted property: Start one pointer at the beginning Another at the end Calculate the sum: If sum is too small → move left pointer forward If sum is too large → move right pointer backward If equal → solution found 🎯 This avoids extra space and keeps the solution super efficient. ⚙️ Complexity Analysis ⏱ Time: O(n) 💾 Space: O(1) Minimal memory, maximum efficiency 💡 🔥 Key Learning Always look for hidden constraints (like sorted input!) Two Pointer technique can replace HashMaps in many cases Clean logic often beats complex code ✅ Solution accepted with excellent runtime & memory performance Another fundamental pattern locked in 🔐 On to Day 50 — halfway milestone loading… 🚀🔥 #100DaysOfCode #LeetCode #Java #TwoPointers #Arrays #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
Day 18 of #100DaysOfCode 🚀 📌 Problem: Isomorphic Strings (LeetCode) 💡 Key Learning: ▪️Two strings are isomorphic if there’s a one-to-one character mapping that stays consistent throughout. 🔍 What I focused on today: ▪️Using HashMap to store character mappings ▪️Ensuring no two characters map to the same value ▪️Understanding the importance of correct if–else structure ▪️Why checking string length first matters ▪️How small logical mistakes can break the entire solution 🧠 Biggest takeaway: Correct logic flow matters more than just writing code that compiles. Consistent practice, clearer logic, and better problem-solving—one day at a time 💪 #Day18 #LeetCode #DSA #Java #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
#PostLog115 𝐂𝐫𝐚𝐜𝐤𝐢𝐧𝐠 𝐑𝐞𝐩𝐞𝐚𝐭𝐞𝐝 𝐒𝐭𝐫𝐢𝐧𝐠 𝐌𝐚𝐭𝐜𝐡 (LeetCode #686) 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐅𝐨𝐥𝐥𝐨𝐰𝐞𝐝: Instead of repeating string 𝐚 endlessly, the idea was to repeat it just enough so that string 𝐛 could possibly fit inside it. 1.Start with an empty string and keep appending 𝐚 until the length becomes at least the length of 𝐛. This ensures we have a fair window where 𝐛 might appear. 2.Check if 𝐛 is a substring at this stage. If yes, we already have the minimum number of repetitions. 3.If not, append 𝐚 one more time and check again. This extra repetition is crucial because 𝐛 can overlap between two consecutive repetitions of a 𝐚 4.If 𝐛 still doesn’t appear, we can safely conclude that it’s impossible. Why this works: A substring can only stretch across at most one boundary between repetitions. Going beyond one extra repetition adds no new possibilities, only extra cost. #PostLog115 #LeetCode #DSA #Java #StringAlgorithms #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode Today’s problem was a very popular array + hashing challenge — Longest Consecutive Sequence 🔢 📌 Problem Summary Given an unsorted array of integers, find the length of the longest consecutive elements sequence. The solution must run in O(n) time. 🧠 My Approach: HashSet Optimization Insert all elements into a HashSet for O(1) lookups Only start counting when the current number is the start of a sequence (i.e., num - 1 does NOT exist in the set) Expand forward while consecutive numbers exist Track and update the maximum sequence length This avoids unnecessary re-counting and keeps the solution efficient. ⚙️ Time & Space Complexity ⏱ Time: O(n) 💾 Space: O(n) (HashSet) 🔥 Key Learning Identifying a valid starting point is crucial for optimal solutions. Hashing combined with smart traversal can turn brute-force ideas into clean O(n) logic. Day 70 done ✔️ Onward to Day 71 🚀 #Day70 #100DaysOfCode #LeetCode #Java #HashSet #Arrays #DSA #ProblemSolving #CodingJourney
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
Nice breakdown 👌 Starting with a clear, intuitive solution and then moving toward optimization is the right mindset. Consistency really is the key—keep going! 🚀