📅 Day 17/100 – LeetCode Challenge 🔹 Problem: 268. Missing Number Today I solved an easy but important array problem where I had to find the missing number from a given range [0, n]. 💡 My Approach: Calculated the expected sum of numbers from 0 to n using formula Calculated the actual sum of elements in the array Subtracted both to find the missing number 🧠 Code Logic: Expected Sum = n * (n + 1) / 2 Missing Number = Expected Sum - Actual Sum 📌 What I Learned: How to use mathematical formulas to optimize problems Avoid unnecessary loops or sorting Improved understanding of array traversal Learned an efficient O(n) solution 🚀 Key Takeaway: Using math-based logic can simplify problems and make solutions faster and cleaner. #Day17 #100DaysOfCode #Java #LeetCode #DSA #Learning
Missing Number Problem Solved with Math Formula
More Relevant Posts
-
🚀 Day 25 of Consistency – LeetCode Journey Today I solved Problem 268: Missing Number on LeetCode. 💡 Approach I Used (Optimal – Math Based): First, I calculated the expected sum of numbers from 0 to n using the formula: 👉 n * (n + 1) / 2 Then: ✅ Calculated the actual sum of all elements in the array ✅ Subtracted actual sum from expected sum 🎯 The result gives the missing number 🧠 Key Learning: This problem shows how a simple mathematical formula can optimize performance and reduce complexity. ⚡ Complexity: • Time: O(n) • Space: O(1) 📌 Consistency is building my problem-solving mindset step by step. #Day25 #LeetCode #DSA #Java #CodingJourney #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 19/100 – LeetCode Challenge 📌 LC 1523 : Count Odd Numbers in an Interval Range Given two integers low and high, return the count of odd numbers between them (inclusive). 🔍 Example: Input: low = 3, high = 7 Output: 3 Odd numbers → 3, 5, 7 🧠 Approach Used: Instead of iterating through the entire range, used a math-based O(1) solution. Formula: (high + 1) / 2 - (low / 2) Why this works? It calculates the number of odd numbers up to high and subtracts the count up to low - 1. ⏱ Time Complexity: O(1) 💾 Space Complexity: O(1) 💡 Key Takeaway: Always look for mathematical patterns in range-based problems to optimize from O(n) to O(1). #Day19 #100DaysOfCode #LeetCode #DSA #CodingJourney #Java #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 70 — LeetCode Practice ✅ Problem Solved: Minimum Operations to Make Array Sum Divisible by K 💡 What I learned today: • Understood how modulus (%) helps in solving optimization problems • Learned that instead of performing operations repeatedly, we can directly use math logic • Realized that the answer depends on sum % k • Improved thinking towards efficient (O(n)) solutions 📊 Approach: • Calculated total sum of the array • Found remainder using sum % k • That remainder itself gives the minimum operations required 🎯 Key Insight: Sometimes, problems look complex but can be solved using simple mathematical observations instead of brute force 🔥 Consistency is the key — showing up every day! #Day70 #LeetCode #DSA #CodingJourney #ProblemSolving #Consistency #Java
To view or add a comment, sign in
-
-
🚀 Day 44/100 Today’s problem: Reverse Vowels of a String. 🔹 Problem Summary: Given a string, reverse only the vowels while keeping other characters in the same position. 🔹 Approach I Used: I applied the Two Pointer Technique: - One pointer from the start, one from the end - Move both until vowels are found - Swap them and continue 🔹 Key Learning: ✔ Two pointers can simplify string problems a lot ✔ Always break the problem into smaller steps ✔ Practice improves pattern recognition. 🔹 Example: Input: "IceCreAm" Output: "AceCreIm" 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(n) Consistency is the key 🔑 — showing up every day! #Day44 #CodingJourney #DSA #Java #Learning #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 19/100 – #100DaysOfCode Challenge Today I worked on an important concept in Binary Search — Lower Bound 🔍 💡 Problem Statement: Find the first index in a sorted array where the value is greater than or equal to a given target (x). ⚡ Key Learning: Lower Bound helps in efficient searching in sorted arrays Instead of linear search (O(n)), we can optimize to O(log n) using Binary Search Very useful in competitive programming & real-world applications 🧠 Approach: Apply Binary Search Store the potential answer Move left to find the smallest valid index ✅ Example: Input: [1,2,2,3], x = 2 Output: 1 💻 What I Practiced Today: Binary Search optimization Edge case handling Writing clean and efficient code 📈 Progress: Improving problem-solving skills step by step! #Day19 #100DaysOfCode #DSA #BinarySearch #CodingJourney #Java #ProblemSolving #Learning
To view or add a comment, sign in
-
-
🚀 Day 16 of LeetCode Problem Solving Solved today’s problem — LeetCode #26: Remove Duplicates from Sorted Array 💻🔥 ✅ Approach: Two Pointers ⚡ Time Complexity: O(n) 📊 Space Complexity: O(1) The task was to remove duplicates in-place from a sorted array and return the count of unique elements. 👉 I used the Two Pointer technique: One pointer to track unique elements Another to traverse the array 💡 Key Idea: Since the array is sorted, duplicates will be adjacent — making it easier to skip them. 👉 Core Logic: Compare nums[i] with nums[j] If different → move pointer and update value Maintain unique elements at the beginning 💡 Key Learning: Two Pointer is a very powerful technique for array problems — especially when data is sorted. Consistency is the key — getting better every day 🚀 #Day16 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 126/500 – LeetCode DSA Challenge Today I solved problems focused on strings and frequency counting. ✅ Ransom Note – Used frequency array to check if the note can be constructed from magazine characters. TC: O(n + m) | SC: O(1) ✅ Find Common Characters – Iteratively found common characters across all strings using string manipulation. TC: O(n × k) | SC: O(k) 💡 Key Learning: Frequency counting is a powerful technique for string problems, and careful string manipulation helps in handling character intersections. 👉 Day 126/500 #DSA #Java #500DaysChallenge #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
🔥 Today’s Learning Update— #Day49 Today I worked on LeetCode 876 — Middle of the Linked List. In arrays, finding the middle is straightforward using length / 2. But in a linked list, we don’t know the length unless we traverse the whole list. 💡 The key idea — Two pointers I used two pointers: 1. Slow pointer → moves one step at a time 2. Fast pointer → moves two steps at a time By the time the fast pointer reaches the end, the slow pointer will be at the middle. This allows us to find the middle in one pass without counting nodes. ⚙️ Complexity ⏱️ Time: O(n) 💾 Space: O(1) 🧠 What I learned today The slow and fast pointer technique is becoming a very useful tool. #Java #DSA #LinkedList #TwoPointers #LeetCode #ConsistencyCurve
To view or add a comment, sign in
-
Day: 97/365 📌 LeetCode POTD: Minimum Distance to the Target Element Easy Key takeaways/Learnings from this problem: 1. This one shows that sometimes the simplest approach—just scanning the array—is more than enough. 2. Key learning: track the minimum absolute distance on the go instead of storing unnecessary data. 3. Good reminder that not every problem needs fancy algorithms, clarity beats complexity. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Day 50/75 — Climbing Stairs Today’s problem was a classic dynamic programming question — counting the number of distinct ways to reach the top. Approach: • Recognize it as a Fibonacci pattern • Each step = sum of previous two steps • Optimize space using two variables instead of an array Key logic: int current = prev1 + prev2; prev2 = prev1; prev1 = current; Time Complexity: O(n) Space Complexity: O(1) A fundamental problem that builds strong intuition for DP and recurrence relations. Halfway there — consistency paying off 🔥 50/75 🚀 #Day50 #DSA #DynamicProgramming #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
Explore related topics
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