🚀 Day 99 - #100DaysOfCode Today’s problem: Left and Right Sum Differences 💡 Approach: Instead of recalculating everything from scratch, I optimized the solution by: Keeping a running leftSum Calculating rightSum dynamically for each index Using Math.abs() to get the absolute difference 🧠 Key Learning: Maintaining a running sum significantly improves efficiency and avoids redundant calculations. #Day99 #CodingJourney #Java #DSA #LeetCode #ProblemSolving #Consistency
Optimizing Left and Right Sum Differences with Running Sums
More Relevant Posts
-
Day 22/100 — LeetCode Today’s problem: Happy Number 😊 At first, it looked like a simple math problem… but it turned out to be about patterns and repetition. 🔍 What I learned: Break a number into digits using % 10 and / 10 Square each digit and keep adding Repeat the process until: You reach 1 → Happy Number ✅ Or it starts repeating → Not Happy ❌ 🧠 Key Insight: This problem is actually about cycle detection — if a number repeats, it will never reach 1. ⚡ Simple Example: 19 → 82 → 68 → 100 → 1 ✅ 💡 Takeaway: Sometimes problems that look like math are really about loops and patterns. Small steps every day → Big improvement 🚀 #Day22 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 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 81 of #LeetCode Journey Solved: Subarray Sums Divisible by K Today’s problem helped me understand the power of Prefix Sum + HashMap optimization. 💡 Key Learning: Instead of checking all subarrays (O(n²)), we can use modulo + frequency map to reduce it to O(n). If two prefix sums have the same remainder, the subarray between them is divisible by K. 🧠 Concepts used: Prefix Sum Modulo Arithmetic HashMap (Frequency Count) ✅ Result: Accepted ✔️ Consistency is building confidence day by day 💪 #Day81 #DSA #Java #LeetCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 60 — LeetCode Practice 🚀 ✅ Problem Solved: Kth Missing Positive Number 💡 What I learned today: • Understood how to find missing numbers in a sorted array • Learned how to compare expected vs actual values • Practiced reducing k step by step to reach the answer • Realized that simple looping logic can solve tricky problems 📊 Approach: • Start from number 1 and compare with array • If number is missing → decrease k • If number is present → move pointer • When k becomes 0 → that number is the answer ⏱ Time Complexity: O(n + k) 📦 Space Complexity: O(1) This problem improved my thinking about sequences and missing elements 🔥 Consistency is the key — Day 60 done! 💪✨ #Day60 #LeetCode #DSA #Java #CodingJourney #KeepGoing
To view or add a comment, sign in
-
-
🚀 Day 20 of My DSA Journey Solved LeetCode Problem #1394 — Find Lucky Integer in an Array 💡 📌 Problem Summary: Given an array of integers, find the largest number whose frequency in the array is equal to its value. If no such number exists, return -1. 🧠 Approach: Used HashMap to store frequency of each element Traversed the map to check if frequency == value Tracked the maximum lucky number 💻 Key Learning: Importance of frequency counting Efficient use of HashMap Writing clean and optimized code using getOrDefault() ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✅ Consistency is the key — small steps every day lead to big results! #Day20 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day #97/100 – LeetCode Challenge 𝐓𝐨𝐝𝐚𝐲’𝐬 𝐩𝐫𝐨𝐛𝐥𝐞𝐦: 𝐂𝐨𝐦𝐛𝐢𝐧𝐚𝐭𝐢𝐨𝐧 𝐒𝐮𝐦 🔹 Problem Summary: Given an array of distinct integers and a target, find all unique combinations where the numbers sum up to the target. Each number can be used multiple times. 🔹𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐔𝐬𝐞𝐝: I solved this using Backtracking (Recursion). . Try including the current element . Explore further combinations . Backtrack and try excluding it . Stop when sum exceeds target 🔹 Key Learning: Backtracking helps in exploring all possible combinations efficiently by building solutions step-by-step and undoing choices when needed. #Day97 #100DaysOfCode #LeetCode #Java #DSA #Backtracking #CodingJourney
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 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
-
🚀 Day 65 #LeetCode Practice ✅ Problem Solved: Minimum Number Game 💡 What I learned today: • Importance of sorting before processing • Understood how to simulate a game step-by-step • Learned swapping elements in pairs efficiently • Improved thinking on pattern-based array problems 📊 Approach: • First, sort the array • Traverse the array in steps of 2 • Swap every pair of elements • Return the modified array 🧠 Key Insight: Sometimes problems look complex, but after sorting, a simple pattern (pair swapping) solves it easily. 🔥 Consistency is the key! Showing up every day is building my problem-solving mindset step by step. #Day65 #LeetCode #DSA #Java #CodingJourney #Consistency #Learning
To view or add a comment, sign in
-
-
🔥 Day 53 of #100DaysOfCode Solved – Number of Steps to Reduce a Number to Zero 🔍 What I did: Simulated the process by repeatedly checking whether the number is even or odd. If even, divided by 2; if odd, subtracted 1 — counting each step until the number became zero. 💡 Key Learning: Strengthened understanding of conditional logic (even vs odd) Practiced step-by-step simulation problems Learned a cleaner approach using bit manipulation (num & 1) ⚡ Result: ✅ Accepted ⚡ Efficient and clean solution 🎯 Takeaway: Breaking a problem into simple rules and simulating them step-by-step can make even tricky problems easy to solve. #Day53 #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode #DSA
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