Day 19/75 🚀 Solved LeetCode 724 — Find Pivot Index today! ✅ All 747/747 test cases passed ⚡ Runtime: 1 ms (Beats 25.74%) 💾 Memory: 35.78 MB (Beats 53.67%) 🔍 Approach — Prefix Sum Logic The goal is to find an index where the sum of elements to the left equals the sum of elements to the right. Here’s how I solved it: First compute the total sum of the array. Maintain a running left sum (currs). For each index: Left Sum = currs Right ends = sum - currs-nums[i]; If both are equal → we found the pivot index. Update currs by adding the current element. This solution runs in O(n) time and uses O(1) extra space. 💡 Key Learning: Prefix sums make array problems much easier. Whenever you need to compare left vs right portions, prefix sum is the perfect approach. Keep building consistency — one problem a day, every day 💪🔥 #LeetCode #LeetCode75 #CPP #DSA #SlidingWindow #ProblemSolving #CodingJourney #75DaysOfCode
Solved LeetCode 724 with Prefix Sum Logic
More Relevant Posts
-
🚀 Day 65/100 – LeetCode Challenge. 🔍 Problem: Remove All Adjacent Duplicates in String. At first glance, this problem looks like a simple string manipulation task… but the real magic lies in using the right approach! 💡 Approach Used: Stack (via string) 👉 Idea: Traverse the string If current character = last character of result → remove it Else → add it 🧠 Key Insight: We simulate a stack using a string. Last added character = top of stack → result.back() ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 📌 Takeaway: Whenever you see adjacent duplicate removal / pair cancellation, think of stack pattern instantly! 💬 Example: Input: "abbaca" Output: "ca" #Day65 #100DaysOfCode #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 26/75 🚀 Solved Decode String (LeetCode 394) today! ✅ All 34/34 test cases passed ⚡ Runtime: 0 ms (Beats 100%) 💾 Memory: 8.22 MB (Beats ~99%) 🔍 Approach: Used a stack-based approach to decode the string. ✔️ Traverse the string character by character ✔️ If character is not ‘]’ → push into result ✔️ When ‘]’ is found: • Extract substring inside brackets • Get the number (repeat count) before '[' • Repeat the substring and append back This continues until the entire string is decoded. 💡 Key Learning: Whenever you see nested patterns (like brackets) → think of stack. It helps manage order and structure efficiently. Consistency + patience = clean solutions 💯 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 31/75 🚀 Solved Maximum Twin Sum of a Linked List (LeetCode 2130) today! ✅ All 46/46 test cases passed ⚡ Runtime: 3 ms (Beats ~67%) 💾 Memory: 124.34 MB (Beats ~67%) 🔍 Approach: Converted the linked list into an array for easy access. ✔️ Stored all node values in a vector ✔️ Used two pointers → one at start, one at end ✔️ Calculated twin sum (list[i] + list[n-1-i]) ✔️ Tracked maximum among all pairs This avoids complex pointer manipulation. 💡 Key Learning: Sometimes extra space simplifies logic a lot. Choosing clarity over optimization can be a smart move. Consistency + smart decisions = efficient solutions 💡 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
🚀 Day 37/75 Solved Path Sum III (LeetCode 437) today! 🌳 ✅ All 130/130 test cases passed ⚡ Runtime: 7 ms (Beats ~59%) 💾 Memory: 18.94 MB (Beats ~76%) 🔍 Approach: Used DFS (recursion) to explore all possible paths in the binary tree. ✔️ For each node, calculated cumulative sum along the path ✔️ Checked if the current sum matches the target ✔️ Started fresh DFS from every node to cover all paths ✔️ Counted all valid paths where sum equals target This ensures we consider every possible path efficiently. 💡 Key Learning: Tree problems often require exploring every node as a starting point. Combining recursion with careful state tracking makes solutions more effective. Consistency + practice = better problem solving 🚀 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode 📌 LeetCode Q3: 3Sum 💡 Problem: Find all unique triplets in the array which gives the sum of 0. 🧠 Approach I Used: - First, sorted the array - Fixed one element - Applied two-pointer technique for the remaining part - Skipped duplicates to avoid repeated triplets ⚡ Key Insight: Instead of brute force O(n³), using sorting + two pointers reduces it to O(n²) ❗ Edge Cases Handled: - Duplicate values - No valid triplets - Negative + positive mix ⏱ Complexity: - Time: O(n²) - Space: O(1) (excluding result) 🔥 Takeaway: Two-pointer + sorting = deadly combo for array problems 💯 💬 Open to feedback & better approaches! #Day70 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 81 / 100 – 100 Days of LeetCode Challenge 🚀 Problem: Absolute Difference Between Maximum and Minimum K Elements (LeetCode #3774) Today I solved the Absolute Difference Between Maximum and Minimum K Elements problem. The task is to select K elements from the array and compute the absolute difference between the maximum and minimum values among those selected elements. Approach I used a sorting-based strategy to organize the elements in ascending order. Once the array was sorted, identifying the minimum and maximum values among the selected K elements became straightforward. Steps followed: • Sort the array in ascending order • Select the required K elements • Identify the minimum and maximum among them • Compute and return their absolute difference This approach simplifies comparisons and ensures accurate results using ordered data. Complexity Time Complexity: O(n log n) Space Complexity: O(1) Result ✔ Accepted ⚡ Efficient runtime 🧠 Sorting and comparison logic A good problem to strengthen understanding of sorting techniques and value comparison in arrays. #100DaysOfCode #100DaysLeetCodeChallenge #LeetCode #DSA #CPlusPlus #ProblemSolving #Sorting #Arrays #regexsoftware
To view or add a comment, sign in
-
-
Day 35/75 🚀 Solved Count Good Nodes in Binary Tree (LeetCode 1448) today! ✅ All 63/63 test cases passed ⚡ Runtime: 91 ms (Beats ~82%) 💾 Memory: 88.34 MB (Beats ~64%) 🔍 Approach: Used DFS (recursion) while tracking the maximum value seen so far on the path. ✔️ Start from root with initial max = root value ✔️ If current node value ≥ max so far → it's a “good node” ✔️ Update max and continue traversal ✔️ Recursively check left and right subtree 💡 Key Learning: Passing state (like max value) in recursion helps solve path-based problems efficiently. No need to store full paths—just keep track of what's important. Consistency + depth thinking = stronger tree skills 🌳🔥 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 63 / 100 – 100 Days of LeetCode Challenge 🚀 Problem: Repeated Substring Pattern (LeetCode #459) Today I solved the Repeated Substring Pattern problem. The task is to determine whether a given string can be constructed by repeating a substring multiple times. Approach Instead of checking every possible substring manually, I used a clever string manipulation trick. I concatenated the string with itself and then removed the first and last characters. If the original string exists inside this modified string, it means the string is formed by repeating a substring pattern. Steps followed: • Create a new string by concatenating the original string with itself • Remove the first and last characters from the new string • Check if the original string exists inside the modified string • If found → return true, otherwise return false This approach simplifies the logic and avoids unnecessary nested loops. Complexity Time Complexity: O(n) Space Complexity: O(n) Result ✔ Accepted ⚡ Efficient runtime 🧠 Smart string manipulation technique A good problem to strengthen understanding of string patterns and thinking beyond brute-force solutions. #100DaysOfCode #100DaysLeetCodeChallenge #LeetCode #DSA #CPlusPlus #ProblemSolving #Strings
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode Day 77/100 – Permutations 🧠 Problem: Given an array of distinct integers, return all possible permutations. 👉 Order matters here → [1,2,3] ≠ [3,2,1] 💡 Core Idea This is a classic Backtracking + Swapping problem 🔥 1️⃣ Fix one element at current index 2️⃣ Swap it with every possible element 3️⃣ Recursively generate permutations for remaining 4️⃣ Backtrack (swap back) 👉 Swap → Recurse → Undo 📚 Key Learnings 1. Backtracking with swapping technique 2. Generating all permutations efficiently 3. Understanding recursion tree deeply ⏱️ Complexity Time Complexity: O(n!) Space Complexity: O(n) (recursion stack) #100DaysOfCode #Day77 #LeetCode #DSA #Backtracking #Recursion #Algorithms #CodingJourney #ProblemSolving #Consistency
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