📅 Day 12 of My DSA Journey 🚀 Today I solved a problem on finding the length of the longest subarray with a given sum using the Prefix Sum + HashMap technique. 🔢 Problem: Given an array arr = [1,2,3,1,1,1,1] and target = 3, find the length of the longest subarray whose sum equals the target. 💡 Approach: • Maintain a running sum (prefix sum) • Use a hashmap to store first occurrence of each sum • Check if (current_sum - target) exists • Calculate subarray length and track maximum 🧠 Key Learning: Storing the first occurrence of prefix sum helps in getting the longest subarray efficiently in O(n) time. ✅ Output: 3 📌 This problem improved my understanding of optimizing subarray problems using prefix sums. #DSA #Python #CodingJourney #100DaysOfCode #Learning #ProblemSolving
Optimizing Subarray Problems with Prefix Sum and HashMap
More Relevant Posts
-
Day 104 Backtracking is all about exploring carefully. #Day104 🧩 79. Word Search How today went: • Explored the grid step by step using DFS + backtracking • Checked if each cell matches the current character in the word • Marked visited cells (like # or temporary value) to avoid reuse • Backtracked by restoring the cell after exploring What I learned: You don’t need to find the whole word at once — just verify one character at a time and move forward. If it fails → backtrack and try another path. Simple idea, but requires careful tracking. #LeetCode #DSA #Python #Backtracking #DFS #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
DSA Tip: Queue If you process tasks in random order… you’ll run into problems. Use a Queue. It follows FIFO (First In, First Out) the first item added is the first to be removed. From print jobs to request handling, queues keep systems organized and fair. Insight: Order isn’t just important, it determines how systems behave. Quick Challenge: If you enqueue A, B, C… which comes out first? Drop your answer, I’ll review the best ones. FOLLOW FOR MORE DSA TIPS & INSIGHTS #DSA #Queue #Python #CodingTips #LearnToCode
To view or add a comment, sign in
-
-
🚀 Day 13 of #100DaysOfDSA Today’s problem was simple but powerful: 👉 Calculate x raised to the power y (x^y) using a while loop. 💡 Key Learning: How to use a loop for repeated multiplication Understanding how exponentiation works internally Strengthening logic-building with basic iteration 🧠 Approach: Initialize power = 1 Multiply x repeatedly y times Decrease y in each iteration ✅ Code (Python): x = int(input()) y = int(input()) power = 1 while y > 0: power *= x y -= 1 print(power) ⚡ Time Complexity: O(y) ⚡ Space Complexity: O(1) 📌 Small problems like this build strong fundamentals for advanced topics like recursion and fast exponentiation. Consistency is the real game 🔥 See you on Day 14! #DSA #Python #CodingJourney #WhileLoop #100DaysChallenge
To view or add a comment, sign in
-
-
🚀 Day 24 of #100DaysOfCode | DSA Journey Today’s focus: Insertion Sort Algorithm 🔄 After exploring other sorting techniques, I dived into Insertion Sort — a simple yet powerful algorithm that works the way we sort playing cards in our hands 🃏 🔹 Key Learnings: - Builds the sorted array one element at a time - Efficient for small datasets and nearly sorted arrays Time Complexity: ⏱ Best Case: O(n) ⏱ Worst Case: O(n²) In-place and stable sorting algorithm 🔹 How it works: - Pick an element - Compare it with previous elements - Shift elements and insert it in the correct position 💡 This helped me understand how basic sorting logic works internally and strengthened my problem-solving approach. Consistency is the key 🔑 — one step closer to mastering DSA! #DSA #100DaysChallenge #InsertionSort #CodingJourney #LearnToCode #Python #SoftwareDevelopment #PlacementPreparation
To view or add a comment, sign in
-
Day 109 Backtracking patterns are repeating again — and that’s a good sign. #Day109 🧩 78. Subsets How today went: • Used recursion to explore all elements • At each step, decide to include or skip the current element • Append current subset → explore → then pop to backtrack • Move to the next index and repeat What I’m noticing: Subsets is one of the cleanest backtracking patterns: → choose → explore → undo Another revision day, but clarity is improving. Consistency continues. #LeetCode #DSA #Python #Backtracking #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 13/100 – Understanding Before Solving Today’s problem: Reverse String At first glance, it looks simple—but the real goal is to understand how to solve it efficiently. The challenge is to reverse the string in-place, meaning without using extra memory. Approach Explained: We use the two-pointer technique: One pointer starts from the beginning One from the end Swap characters and move inward This avoids creating a new array and keeps the solution optimal. Time Complexity: O(n) Space Complexity: O(1) Key Learning: Writing code is important, but understanding why it works is what truly builds strong problem-solving skills. One step closer to mastering DSA. #100DaysOfCode #DSA #Learning #ProblemSolving #Python #LeetCode #GrowthMindset
To view or add a comment, sign in
-
-
Day 105 Backtracking is becoming more structured now. #Day105 🧩 131. Palindrome Partitioning How today went: • Iterated through the string, taking one substring at a time • Used DFS to explore partitions • Checked if each substring is a palindrome before going deeper • Built the result step by step and backtracked when needed What clicked: At each step: → choose a substring → validate (palindrome) → explore further → backtrack This pattern is repeating across problems. Backtracking is slowly becoming more intuitive. #LeetCode #DSA #Python #Backtracking #DFS #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 25 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem: Search a 2D Matrix (#74) 💡 Key Learning: This problem teaches how to apply binary search on a 2D matrix by treating it as a flattened sorted array. It’s all about visualizing the structure differently. ⚡ Approach: First apply binary search on rows to find the potential row Check range using first and last element of each row Once row is identified → apply binary search on that row Return true if target found, else false 🧠 Why this works: Matrix follows sorted properties row-wise and across rows Binary search efficiently reduces search space Achieves optimal time complexity → O(log(m × n)) 🔥 Result: ✔️ Runtime: 0 ms (Beats 100%) 📈 This is a classic problem combining matrix + binary search, frequently asked in interviews. A big thanks to Shivam Singh, Nikhil Yadav & Akshat Tiwari for this amazing challenge 🙌 Consistency is compounding. Keep going. 💪 #Day25 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #BinarySearch #Consistency
To view or add a comment, sign in
-
-
🚀 Day 12 of Consistency | #75DaysLeetCodeChallenge 🧠 Today’s Problem : 3Sum (#15) 💡 Key Learning: This problem teaches how to efficiently find triplets using sorting + two-pointer technique, while carefully handling duplicates. ⚡ Approach: Sort the array → fix one element (i) → use two pointers (l, r) → If sum == 0 → store triplet & skip duplicates If sum < 0 → move l++ If sum > 0 → move r-- 🧠 Why this works: Reduces complexity from O(n³) → O(n²) Avoids duplicate triplets Efficient use of sorting + two pointers 🔥 Result : ✔️ Runtime: 574 ms (Beats 75.21%) 📈 Problems like this build strong intuition for tackling complex array & pattern-based questions. Consistency is compounding. Keep going. 💪 #Day12 #LeetCode #DSA #CodingJourney #100DaysOfCode #Python #TwoPointers #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