Day 35 / 100 – Subarray Sum Equals K (LeetCode #560) Today’s challenge was about finding the number of continuous subarrays whose sum equals a given value k. At first, the brute-force approach felt tempting — checking every possible subarray — but that would be too slow. Instead, I learned to use a Hash Map to store cumulative sums and find the solution in linear time. This problem truly deepened my understanding of prefix sums and how storing previous computations can make complex problems simple and elegant. 🔍 Key Learnings Prefix Sum helps keep track of cumulative totals efficiently. Hash Maps allow quick lookups, reducing time complexity from O(n²) to O(n). Sometimes, the key to optimization is remembering what you’ve already calculated. 💭 Thought of the Day Today reminded me that not every problem needs to be solved from scratch — sometimes, the best solutions come from building on what you already know. Logic and memory, when used together, create magic in code ✨ 🔗 Problem Link: https://lnkd.in/gVGGGm6J #100DaysOfCode #Day35 #LeetCode #Python #HashMap #ProblemSolving #DataStructures #Algorithms #CodingChallenge #CodeEveryday #LearningJourney #Optimization #CleanCode #TechGrowth
Solved LeetCode #560 with Hash Map and Prefix Sum
More Relevant Posts
-
Day 39 / 100 – Combination Sum (LeetCode #39) Today’s challenge was Combination Sum, a classic problem that teaches how to explore all possible combinations that add up to a target. The key idea here is recursion with backtracking — trying different paths, and “undoing” choices when they don’t lead to a solution. At first, it felt complex to keep track of combinations without duplicates, but recursion made it elegant once I understood how to structure the calls properly. It’s a great example of how backtracking mirrors human problem-solving: try, fail, and refine until success. 🔍 Key Learnings Recursion helps break complex problems into smaller, reusable patterns. Backtracking avoids unnecessary computation by pruning invalid paths early. Always remember to copy the current combination when adding it to results — lists are mutable! 💭 Thought of the Day Sometimes the most powerful solutions come from simplicity — recursion mirrors the way we naturally think through problems step by step. Today’s problem reminded me that patience and clarity often lead to clean, beautiful solutions ✨ 🔗 Problem Link: https://lnkd.in/gxtE573Z 🏷️ #100DaysOfCode #Day39 #LeetCode #Python #Recursion #Backtracking #ProblemSolving #Algorithms #DataStructures #CodingChallenge #LearnToCode #CleanCode #MindsetMatters #CodeEveryday #TechJourney
To view or add a comment, sign in
-
-
🧠 Day 13 — Thinking in Ranges, Not Just Numbers Today’s LeetCode problem was “Maximum Frequency of an Element After Performing Operations I.” At first, it felt straightforward — perform up to numOperations changes on elements within a range of [-k, k] to maximize frequency. But once I got into it, I realized the real challenge wasn’t the operations — it was understanding how intervals overlap and interact. Here’s the logic I built around it: 🔹 Each number can shift within [num - k, num + k], forming a range of possible values. 🔹 The goal is to find how many such ranges overlap at any point — that overlap represents the maximum achievable frequency. 🔹 I used sorted events and a sweep line approach to track how many intervals are active at any moment. 🔹 The maximum overlap gives the answer — the highest number of elements that can become equal after allowed operations. This problem wasn’t just about code; it was about thinking visually — seeing numbers as segments on a line rather than static values. That shift in perspective changed how I approached it. Thanks to Shishir chaurasiya sir and PrepInsta team One more day, one more layer of understanding peeled back. #Day13 #LeetCode #ProblemSolving #100DaysOfCode #Python #Algorithms #DataStructures #KeepBuilding #DevMindset
To view or add a comment, sign in
-
-
🌳 DSA Challenge – Day 100 🎉 Problem: Construct Binary Tree from Preorder and Inorder Traversal 🌲 We made it to Day 100 of the challenge! 💪🔥 Let’s end this journey with a classic Tree Construction problem — a perfect blend of recursion, hashing, and traversal logic. 🧠 Problem Summary: You’re given two integer arrays: preorder → preorder traversal of a binary tree inorder → inorder traversal of the same tree Your goal: Reconstruct and return the binary tree. ⚙️ My Approach: 1️⃣ The first element of preorder is always the root. 2️⃣ Use a hash map (index) to quickly find the root’s position in the inorder array. 3️⃣ Recursively build: The left subtree from elements before the root in inorder. The right subtree from elements after the root in inorder. 4️⃣ Reversing preorder allows efficient pop() operations from the end (O(1)). 💡 Why This Works: Preorder gives the root order, Inorder gives the structure (left–root–right). By combining both, we can rebuild the entire tree recursively in O(n) time. 📈 Complexity Analysis: Time Complexity: O(n) — Each node is processed once, and lookup is O(1) using a hash map. Space Complexity: O(n) — For recursion + hash map. ✨ Key Takeaway: Efficient recursion often comes from using traversal properties smartly — here, preorder identifies roots, while inorder defines subtree boundaries. 🌟 Milestone Moment: That’s Day 100 of DSA 🔥 From arrays to trees, recursion to heaps — what a journey! 🌱 Keep learning, keep building, and keep challenging yourself 💪 🔖 #Day100 #100DaysOfCode #DSA #BinaryTree #Preorder #Inorder #LeetCode #Recursion #Python #DataStructures #ProblemSolving #CodingChallenge #TechCommunity #Milestone
To view or add a comment, sign in
-
-
Day 32 / 100 – Single Number III (LeetCode #260) Today’s challenge was about identifying two unique numbers in an array where every other number appears exactly twice. The twist — it had to be solved in linear time and with constant space. This problem helped me dive deeper into bitwise operations, showing how simple binary logic can reveal elegant patterns hidden inside data. 🔍 Key Learnings XOR can be used to cancel out duplicates and isolate unique values. The rightmost set bit helps separate numbers into logical groups. Bit manipulation offers a powerful way to write optimized and clean algorithms. 💭 Thought of the Day Today reminded me that clever thinking often beats complex logic. When we focus on how data behaves at the bit level, we unlock a new layer of understanding — one that turns code into pure logic. Progress isn’t about solving more; it’s about solving smarter. 🔗 Problem Link:https://lnkd.in/gNjjkBni #100DaysOfCode #Day32 #LeetCode #Python #ProblemSolving #BitManipulation #CodingChallenge #Algorithms #DataStructures #TechGrowth #LearningJourney #CodeEveryday
To view or add a comment, sign in
-
-
⚡ Day 83 of #100DaysOfDSA – Majority Element 💡 📌 Problem. no 169: Given an array nums, find the element that appears more than ⌊n / 2⌋ times. Implemented an efficient hash map-based counting approach to track element frequency and determine the majority element quickly. ⚡ Runtime: 13 ms – Beats 37.81% of submissions 💾 Memory: 13.60 MB – Beats 64.79% of solutions 💻 Language Used: Python ✅ Status: Accepted – All 53 test cases passed successfully! This challenge helped me better understand frequency counting, dictionary operations, and threshold-based decision making. It’s a great problem for mastering counting logic and handling arrays efficiently. 🔑 Key Learnings: ✔️ Strengthened my understanding of hash maps and element frequency counting ✔️ Learned how to use early termination for optimization ✔️ Improved confidence in solving majority and occurrence-based problems 🎯 Day 83 — A solid step forward in mastering counting logic and data structure efficiency! 🚀🔥 #100DaysOfCode #100DaysOfDSA #LeetCode #PythonProgramming #DataStructures #AlgorithmPractice #CodeNewbie #DailyCoding #ProblemSolving #TechJourney #WomenWhoCode #CodeLife #CodingChallenge #DSAChallenge #DeveloperLife #PythonDeveloper #LearnToCode #CodingCommunity #CodeEveryday #SoftwareEngineering #KathirCollegeOfEngineering #KathirCollege #BTechLife #AIDS #FutureEngineer #CodingMotivation #ProgrammingSkills
To view or add a comment, sign in
-
-
💯 Day 46 / 100 – 100 Days of #LeetCode Challenge 🔁 Problem: 326. Power of Three Goal: Given an integer n, return true if it is a power of three. Otherwise, return false. An integer n is a power of three if there exists an integer x such that n == 3ˣ. Approach: ✅ Initialize a list with [1] (since 3⁰ = 1). ✅ Iterate from 1 to n, compute powers of 3 using temp = 3 ** i. ✅ Break the loop if temp > n. ✅ Store valid powers in a list and check if n exists in it. Complexity: ⏱ Time: O(log₃n) – since powers of 3 grow exponentially. 🗂 Space: O(log₃n) – storing powers of 3 up to n. 💡 Key Takeaway: Patterns like “power of a number” can be generalized using loops and exponentiation. Recognizing exponential growth helps optimize logic for mathematical problems. #100DaysOfLeetCode #Day46 #Python #Math #ProblemSolving #LeetCode #CodingChallenge #PowerOfThree #LogicalThinking
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about frequency mapping and subarray logic — solving the Picking Numbers problem from HackerRank. 🔗 Problem: pickingNumbers(a) (HackerRank) 📌 Challenge: Given an array of integers, find the length of the longest subarray where the absolute difference between any two elements is ≤ 1. 🔍 Approach: → Used Python’s Counter to map frequencies of each number → For each number num, calculated freq[num] + freq[num + 1] → Tracked the maximum such sum to find the longest valid subarray → Avoided brute-force by leveraging frequency patterns instead of scanning all subarrays 💡 What made it click: → Realized that valid subarrays must contain only num and num + 1 → Frequency mapping reveals hidden structure in the data → Clean logic with max() and get() made the solution elegant and readable 📚 What I learned: ✅ Frequency-based thinking can simplify subarray problems ✅ Counter is a powerful tool for pattern detection ✅ Avoiding brute-force leads to scalable, efficient solutions ✅ Sharing dry runs and visual walkthroughs helps others grasp the intuition faster Have you tackled Picking Numbers before? Did you go with sorting, brute-force, or frequency mapping like I did? Let’s swap strategies 💬 #Day31 #HackerRank #SubarrayLogic #FrequencyMapping #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 36 / 100 – Longest Palindromic Substring (LeetCode #5) Today’s challenge focused on String Manipulation — finding the longest palindromic substring within a given string. At first, it felt tricky to handle all the possible substrings, but then I learned to expand around the center, checking for symmetry on both sides. This approach makes the solution both logical and efficient. This problem reinforced how clarity in logic often comes from recognizing patterns, and that even complex problems can be broken into smaller, mirror-like checks. 🔍 Key Learnings Expanding around the center efficiently checks for palindromes in O(n²) time. Always consider both even and odd length palindromes. String problems often rely on clear thinking more than heavy algorithms. 💭 Thought of the Day Problem-solving isn’t about rushing for the answer — it’s about exploring the structure of the challenge. Palindromes taught me patience, symmetry, and the art of looking for balance in both logic and code. 🔗 Problem Link: https://lnkd.in/gSe-ygD8 #100DaysOfCode #Day36 #LeetCode #Python #StringManipulation #ProblemSolving #Algorithms #CodingChallenge #CleanCode #CodeEveryday #LearningJourney #DataStructures #Optimization
To view or add a comment, sign in
-
-
🌳 Day 12 of 30 – LeetCode Challenge: Symmetric Tree 🔁 Today’s challenge was about determining if a binary tree is symmetric — meaning it is a mirror of itself around its center. This is a classic Binary Tree + Recursion problem that also builds intuition for mirror-based traversal. 🧩 Problem Summary Given the root of a binary tree, check if it is symmetric. ✅ Example 1 Input: [1,2,2,3,4,4,3] Output: true ❌ Example 2 Input: [1,2,2,null,3,null,3] Output: false 💡 Logic A tree is symmetric if: Left subtree of L mirror-matches Right subtree of R i.e., L.val == R.val L.left mirrors R.right L.right mirrors R.left ⚙️ Complexity Analysis Recursion Time:O(n) Space:O(h) Iterative Time:O(n) Space:O(n) 🏆 Takeaways ✅ Improved understanding of tree symmetry and mirror traversal 🧠 Strengthened concepts of recursion & queue-based BFS 🌱 Setting up a strong foundation for Binary Tree & DFS/BFS concepts #Day12 #LeetCode #BinaryTrees #Recursion #Iteration #Python #WomenWhoCode #DSA #CodingChallenge #30DaysOfCode #MTech #LearningEveryday
To view or add a comment, sign in
-
-
💡 Day 18 of 30 – LeetCode Challenge: Maximum Depth of Binary Tree Today’s problem helped me strengthen my understanding of Tree Traversal and Recursion in binary trees — a core concept in data structures. 🧩 Problem Summary Given the root of a binary tree, return its maximum depth, which is the number of nodes along the longest path from the root to the deepest leaf node. ⚙️ Example Input: root = [3,9,20,null,null,15,7] Output: 3 📖 Explanation: The longest path is 3 → 20 → 7 (or 3 → 20 → 15), which contains 3 nodes — so the maximum depth is 3. 🧠 Approach We can solve this using recursion — If the current node is None, return 0 (base case). Recursively find the depth of the left and right subtrees. The maximum depth is 1 + max(left_depth, right_depth). ⏱ Complexity Analysis Time Complexity O(n) — each node is visited once Space Complexity O(h) — recursion stack (h = tree height) ✨ Key Learnings ✅ Understood how recursion elegantly breaks down hierarchical structures like trees. ✅ Reinforced the concept of base cases in recursive solutions. ✅ Realized how traversal patterns (preorder, inorder, postorder) apply in different problem contexts. #Day18 #LeetCode #BinaryTree #Recursion #DSA #CodingChallenge #Python #WomenWhoCode #LearningJourney #ProblemSolving
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