Day 5 of Daily DSA 🚀 Solved LeetCode 268: Missing Number Approach: Used the mathematical sum formula to calculate the expected sum of numbers from 0 to n. Subtracted the actual sum of array elements to find the missing number in a single pass. Complexity: • Time: O(n) • Space: O(1) LeetCode Stats: • Runtime: 0 ms (Beats 100%) • Memory: 47.57 MB A simple yet powerful problem that shows how math can replace extra space and lead to clean, efficient solutions. #DSA #LeetCode #Java #ProblemSolving #Arrays #Consistency
Missing Number in Array: LeetCode 268 Solution
More Relevant Posts
-
Day 9 of DSA Practice | LeetCode 268 – Missing Number Solved Missing Number, focusing on using the Mathematical Formula approach to find the missing value efficiently. Concept Used: Sum of first n natural numbers Approach: Compare expected sum n(n+1)/2 with the actual array sum Time Complexity: O(n) Space Complexity: O(1) This problem helped reinforce: • Array traversal • Mathematical optimization • Writing efficient solutions Learning and improving one problem at a time #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
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 82/100 – LeetCode Challenge ✅ Problem: #43 Multiply Strings Difficulty: Medium Language: Java Approach: Manual Multiplication with Result Array Time Complexity: O(n × m) Space Complexity: O(n + m) Key Insight: Multiply digits from right to left (least significant first). Store intermediate results in array where index i + j + 1 holds current digit. Handle carry by adding to previous index. Solution Brief: Edge case: if either number is "0", return "0". Created result array of size n1 + n2 (max possible digits). Nested loops multiply each digit of num1 with each digit of num2. Accumulated results with proper carry handling. Built final string skipping leading zeros. #LeetCode #Day82 #100DaysOfCode #Math #String #Java #Algorithm #CodingChallenge #ProblemSolving #MultiplyStrings #MediumProblem #Multiplication #Array #DSA
To view or add a comment, sign in
-
-
LeetCode 268 – Missing Number Today I solved “Missing Number”, a simple but powerful DSA problem. Problem summary: Given an array containing n distinct numbers in the range [0, n], return the one number that is missing from the array. What I learned from this problem: • We can solve it using sorting (but that’s not optimal) • A better approach is using the Sum Formula Expected sum = n × (n + 1) / 2 Missing number = Expected sum − Actual sum • Time Complexity: O(n) • Space Complexity: O(1) Another interesting approach is using XOR, which avoids overflow and also runs in O(n) time. This problem reminded me that sometimes the best solution is not complicated — it’s about recognizing mathematical patterns. Small problems like this build strong problem-solving intuition. #DSA #LeetCode #ProblemSolving #Java #CodingJourney #LearningInPublic
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 25 of Practicing DSA on LeetCode Solved: • (540) Single Element in a Sorted Array – Medium Focused on: -Applying binary search on index patterns -Using even–odd index logic to narrow the search space -Achieving O(log n) time with O(1) extra space -Avoiding brute force by trusting array structure This problem showed how sorted data + index patterns = powerful optimizations. Think in patterns, not positions. Consistency over everything. #DSA #Java #LeetCode #BinarySearch #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 72/100 – LeetCode Challenge ✅ Problem: #7 Reverse Integer Difficulty: Medium Language: Java Approach: Digit Extraction with Overflow Check Time Complexity: O(log₁₀ x) Space Complexity: O(1) Key Insight: Reverse integer by repeatedly extracting last digit and building result. Critical: Check overflow before final cast using long to detect > Integer.MAX_VALUE or < Integer.MIN_VALUE. Solution Brief: Extracted digits using modulo 10. Built reversed number step by step in long to detect overflow. After loop, divided by 10 to remove extra multiplication. Checked if result fits in 32-bit integer range. Handled sign separately at the end. #LeetCode #Day72 #100DaysOfCode #Math #Java #Algorithm #CodingChallenge #ProblemSolving #ReverseInteger #MediumProblem #Overflow #DigitManipulation #DSA
To view or add a comment, sign in
-
-
Day 17 of DSA practice 🚀 (Deep Dive into Binary Search) Today I solved Problem #4 – Median of Two Sorted Arrays — and it was a really insightful one. Instead of merging the two sorted arrays (which would take O(n + m) time), I learned a smarter approach to find the median without actually creating the combined array. Key takeaways: 1) Using binary search on partitions instead of values 2) Dividing the arrays in a way that left partition ≤ right partition 3) Achieving O(log(min(n, m))) time complexity Beyond the algorithm, I also learned something important about code design: The importance of separation of concerns. Breaking the logic into clear responsibilities made the solution more readable, easier to debug, and conceptually simpler — even for a complex problem. Today wasn’t just about solving a hard problem, it was about improving how I think and structure solutions 🔥 #DSA #LeetCode #BinarySearch #Algorithms #ProblemSolving #CleanCode #Java #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
Day 18 – Solving 3Sum (LeetCode) Today I solved the 3Sum problem on LeetCode using an optimized approach 💻 🔹 Problem: Given an integer array, find all unique triplets whose sum is 0. 🔹 Example: Input: [-1, 0, 1, 2, -1, -4] Output: [[-1, -1, 2], [-1, 0, 1]] 🧠 What I learned How sorting helps reduce unnecessary comparisons How to use the two-pointer technique How to avoid duplicate triplets ⚙️ Approach Sort the array Fix one element Use two pointers to find the remaining two elements Skip duplicates This reduces time complexity from O(n³) to O(n²) 💡 Improving my Data Structures & Algorithms skills one day at a time #Day18 #LeetCode #3Sum #DSA #Java #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Day 6 of Daily DSA 🚀 Solved LeetCode 977: Squares of a Sorted Array Approach: Used the two-pointer technique to compare squares from both ends of the array and build the result from back to front. This avoids extra sorting and keeps the solution optimal. Complexity: • Time: O(n) • Space: O(n) LeetCode Stats: • Runtime: 1 ms (Beats 99.80%) • Memory: 47.21 MB (Beats 74.22%) This problem reinforced how understanding data patterns can help eliminate unnecessary operations like sorting. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #100DaysOfCode
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