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
LeetCode 268: Missing Number Solution with Math Formula
More Relevant Posts
-
Day 29 of Daily DSA 🚀 Solved LeetCode 287: Find the Duplicate Number ✅ Problem: Given an array containing n + 1 integers where each number is in the range [1, n], find the duplicate number. Approach: Used the index marking technique. Key Idea: Treat the value as an index Convert the value to absolute (Math.abs) Mark the visited index by making the number negative If we encounter an index that is already negative, that value is the duplicate This allows us to detect duplicates efficiently without extra space. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 4 ms (Beats 91.67%) ⚡ • Memory: 82.75 MB A clever trick that uses the array itself as a visited map. #DSA #LeetCode #Java #ProblemSolving #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 48 – DSA Journey 🚀 | Smallest Number With All Set Bits Continuing my daily DSA practice, today I solved a bit manipulation problem that highlights the importance of recognizing patterns in binary numbers. 📌 Problem Practiced: Smallest Number With All Set Bits (LeetCode 3370) 🔍 Problem Idea: Given a number n, find the smallest number x ≥ n whose binary representation contains **only 1s`. 💡 Key Insight: Numbers with all set bits follow the pattern 2^k − 1 (e.g., 1, 3, 7, 15...). We can generate these numbers directly using bit manipulation instead of checking every value. 📌 Concepts Strengthened: • Bit shifting (<<) • Bitwise OR (|) • Binary pattern recognition ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) Today’s takeaway: Recognizing binary patterns can simplify many bit manipulation problems and lead to cleaner solutions. On to Day 49! 🚀 #Day48 #DSAJourney #LeetCode #BitManipulation #Java #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 10 of DSA Practice | LeetCode 153 – Find Minimum in Rotated Sorted Array Today I solved the problem Find Minimum in Rotated Sorted Array using a Binary Search approach. This problem focuses on identifying the minimum element in a rotated sorted array while maintaining an optimal time complexity. Key concepts applied: • Binary Search on rotated arrays • Comparing mid and boundary elements • Optimized search logic Time Complexity: O(log n) Space Complexity: O(1) Daily practice on LeetCode is helping me strengthen my understanding of algorithms and improve problem-solving skills step by step. #DSA #LeetCode #BinarySearch #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 48 of My DSA Journey Solved: Roman to Integer (LeetCode #13) Today’s problem focused on understanding how Roman numerals translate into integers using mapping and pattern recognition. 🔍 Key Learnings: • Learned how to use a HashMap for value mapping • Understood the concept of subtractive notation (like IV = 4, IX = 9) • Improved my ability to handle string traversal with conditions • Strengthened logic-building for edge cases 💡 Approach: Instead of simply adding values, I checked if the current symbol is smaller than the next one. If yes → subtract logic If no → add normally 📌 This problem helped me realize how small conditions can change the entire logic flow. #Day48 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 85/100 – LeetCode Challenge ✅ Problem: #226 Invert Binary Tree Difficulty: Easy Language: Java Approach: Recursive DFS (Divide and Conquer) Time Complexity: O(n) Space Complexity: O(h) where h = tree height Key Insight: Swap left and right child at every node, then recursively invert both subtrees. Classic recursion problem — made famous by Google interview story. Solution Brief: Base case: if root is null, return null. Swap left and right children using temporary variable. Recursively call invertTree on left and right subtrees. Return the root (now inverted). #LeetCode #Day85 #100DaysOfCode #Tree #Java #Algorithm #CodingChallenge #ProblemSolving #InvertBinaryTree #EasyProblem #DFS #Recursion #DSA
To view or add a comment, sign in
-
-
Day 61 of My DSA Journey Today I solved the Subsets problem using the Backtracking technique. 🔹 Problem: Given an integer array nums, return all possible subsets (the power set). 🔹 Key Idea: Instead of trying to generate subsets directly, I used backtracking to explore every possible combination. 💡 Approach: Start with an empty subset. At each step, add the current subset to the result. Try including each element one by one. Recursively explore further subsets. Backtrack by removing the last element to explore other possibilities. 🔁 This approach systematically explores every possible subset using a decision tree. 📊 Time Complexity: O(n × 2ⁿ) — because each element can either be included or excluded. ✨ What I Learned: Backtracking is powerful for solving combinatorial problems. The pattern of choose → explore → unchoose is very important. 💻 Practicing problems like this helps strengthen recursion and problem-solving skills. #Day61 #DSA #Backtracking #Java #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day 7 #SDE Problems involving Binary Search on the answer space and distance-based computations. Solved: • 719. Find K-th Smallest Pair Distance • Sum of Manhattan Distances between all pairs of points Key Learning: Many problems involving pair distances can be optimized by combining sorting + binary search on the answer with efficient counting techniques. Also explored how mathematical observations help compute Manhattan distance sums more efficiently instead of checking every pair. #LeetCode #DSA #BinarySearch #Algorithms #Java #SoftwareEngineering
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
-
-
Day 79 of DSA Problem Solving Solved LeetCode 137 — Single Number II 🔥 Today’s problem was all about bit manipulation and thinking beyond the usual hashmap approach. 🚀 Problem Idea We are given an array where every number appears three times, except one number that appears only once. The task is to find that unique number in linear time and with constant extra space. 💡 Key Learning The main insight was: If we count how many times each bit is set across all numbers, then for bits belonging to numbers appearing 3 times, the count will be a multiple of 3, and the leftover bits will belong to the number that appears once. So by checking each of the 32 bit positions, we can rebuild the answer. 🧠 Concepts Practiced Bit Manipulation Bitwise Shift Bitwise AND Modulo with bit counts Building number from bits ⏱ Time Complexity Time: O(32 × n) ≈ O(n) Space: O(1) 📈 Real Journey Behind the Solution At first, this problem looks like it can be solved using a frequency map. But the condition of constant space pushes us to think deeper. This question helped me understand how bits can be used to optimize space and still solve the problem efficiently. A very good example of how constraints guide us toward the intended approach. Every day, I’m realizing that DSA is not just about solving problems, but about training the mind to observe patterns from a different angle. #Day79 #DSA #LeetCode #Java #BitManipulation #CodingJourney #ProblemSolving #SoftwareEngineering #CodingDaily
To view or add a comment, sign in
-
-
🚀 Day 63 of #100DaysOfLeetCode ✅ Problem Solved: Unique Binary Search Trees (LeetCode 96) Today’s problem was a great example of how Dynamic Programming and mathematical patterns (Catalan Numbers) come together. 🔍 Key Insight: For every node chosen as root, the number of unique BSTs is: 👉 Left Subtrees × Right Subtrees This leads to the recurrence: dp[n] = Σ (dp[left] × dp[right]) 💡 What I learned: Breaking problems into smaller subproblems makes complex structures easier Recognizing patterns like Catalan Numbers is a game changer DP is not just about arrays, it's about thinking smart ⚡ Result: ✔️ Runtime: 0 ms (Beats 100%) ✔️ Clean and optimized solution Consistency is slowly turning into confidence 💪 #LeetCode #DataStructures #DynamicProgramming #CodingJourney #ProblemSolving #Java #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