=>Day 17/90 DSA Journey Solved: Continuous Subarray Sum (LeetCode) Today I worked on an interesting problem involving Prefix Sum + HashMap, which helped me optimize from a brute-force O(n²) solution to an efficient O(n) approach. If the same remainder (sum % k) appears again, it means the subarray between those indices has a sum divisible by k. -> What I learned: How to use prefix sum effectively Importance of storing remainders in HashMap Handling edge cases like subarray length ≥ 2 ->Optimization: Brute Force → O(n²) ❌ Optimized Approach → O(n) ✅ #LeetCode #DSA #Java #Coding #ProblemSolving #100DaysOfCode
Optimizing Continuous Subarray Sum with Prefix Sum and HashMap
More Relevant Posts
-
Day 5/30 of #30DaysOfDSA 🔹 Problem: Decode String 💡 Approach: Used a stack-based approach to handle patterns like k[encoded_string], especially nested ones. Stored counts and previous strings, and built the result step-by-step while traversing. ⚡ What I Learned: • Handling nested structures using stacks • Efficient string building • Optimizing parsing logic Complexity: O(n) #DSA #Coding #Java #Consistency
To view or add a comment, sign in
-
-
Day 82 of DSA Journey Solved Isomorphic Strings today! This problem looks simple, but it teaches an important concept — one-to-one mapping between characters. 🔍 What I learned: Each character in one string must map to exactly one character in the other No two characters should map to the same character Consistency across the entire string is key 💡 Approach: Used two HashMaps to track mappings in both directions: s → t t → s This avoids conflicts and ensures correctness. 🧠 Example: "paper" → "title" ✅ "foo" → "bar" ❌ ✨ Key takeaway: Always think about bidirectional mapping when dealing with transformation problems. Small problem, but powerful concept! #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
#Day361 of #1001DaysOfCode 📘 LeetCode Daily Challenge Problem: XOR After Queries 💡 Approach: Simulated each query by updating elements in the array based on the given step and multiplier, and finally computed the XOR of all elements. This approach works correctly but can be further optimized for large inputs using better range update techniques. ⏱ Time Complexity: O(q * n) 🧠 Space Complexity: O(1) Learning to identify optimization opportunities in problems 🚀 #DSA #Java #LeetCode #ProblemSolving #Coding
To view or add a comment, sign in
-
-
🚀 Day 7 of #LeetCode Challenge 🔍 Problem: Sqrt(x) 💡 Approach: Used the built-in Math.sqrt() function to compute the square root and then typecasted it to an integer to get the floor value. 🧠 Key Concept: Understanding how to convert a floating-point result into an integer using typecasting. 🔥 #Day7 #LeetCode #Java #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟕𝟕 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding all elements that appear more than n/3 times in an array. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Majority Element II 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐇𝐚𝐬𝐡𝐌𝐚𝐩 • Counted frequency of each element using a map • Calculated threshold = n / 3 • Collected elements whose frequency exceeded the threshold 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • At most 2 elements can appear more than n/3 times • HashMap is straightforward for frequency counting • Understanding constraints helps reduce possibilities • This problem has an optimized Boyer-Moore Voting (extended) solution 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(n) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Constraints often reveal hidden patterns — understanding them leads to better optimizations. 77 days consistent 🚀 On to Day 78. 🔗 Problem Link: https://lnkd.in/dDwdWYJs #DSA #Arrays #HashMap #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 35 of Consistency 💻🔥 Solved Longest Substring Without Repeating Characters — a classic sliding window problem that really tests optimization skills. ✨ Key Takeaways: Mastered the sliding window technique Used HashMap for efficient lookup Improved understanding of two-pointer approach ⚡ Performance: Runtime: 5 ms Beat: 87%+ submissions Every day is about getting sharper, not just solving problems. #LeetCode #DataStructures #Algorithms #CodingJourney #Consistency #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀Solved Validate Stack Sequences by simulating the stack using a simple array instead of relying on built-in stack classes. This helped reduce overhead and kept the operations efficient. Focused on writing clean logic with optimal time complexity. 😊 Result: 💯 Achieved 0 ms runtime beating 100% of submissions, with memory usage around 45.52 MB performing in the top percentile. 💥 #LeetCode #DSA #Java #Coding #ProblemSolving #Preparation #Anurag_University 🚀🚀
To view or add a comment, sign in
-
-
#Day76 of my second #100DaysOfCode Binary search continues to surprise me with how many variations it has. DSA • Solved Find Peak Element (LeetCode 162) – Brute: check every element → O(n) – Optimal: binary search based on slope comparison → O(log n) • Key idea: if the next element is greater, move right; else move left — a peak is guaranteed • Didn’t need to check all elements, just follow the increasing/decreasing trend Interesting how this doesn’t require a fully sorted array, yet binary search still works. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 69 — LeetCode Practice 🚀 Today’s focus was on string manipulation and careful indexing. ✅ Problem solved today: 🔹 Find Common Characters 💡 Key learnings from today: • Understood how to find common characters across multiple strings • Learned the importance of character frequency counting • Practiced handling nested loops efficiently • Realized how small mistakes in indexing can affect the entire logic • Improved attention to detail while working with strings Initially, I made a mistake by using the wrong variable inside charAt(). This caused incorrect indexing, which can either lead to wrong output or even StringIndexOutOfBoundsException. After fixing it, the logic worked perfectly by correctly comparing characters and tracking their minimum frequency across all words. This problem reinforced an important lesson: Sometimes errors are not in logic — but in small details like indexing and variable usage. Accuracy matters as much as logic. Step by step, getting better 💪 On to Day 70 🚀 #Day69 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #FutureEngineer
To view or add a comment, sign in
-
-
Day 92 of #100DaysOfLeetCode 💻✅ Solved #739. Daily Temperatures problem in Java. Approach: • Used Monotonic Stack to track indices • Compared current temperature with stack top • Updated result when a warmer day was found • Stored indices for future comparisons Performance: ✓ Runtime: 60 ms (Beats 79.01% submissions) 🚀 ✓ Memory: 107.89 MB (Beats 17.53% submissions) Key Learning: ✓ Learned Monotonic Stack technique ✓ Improved handling of next greater element problems ✓ Strengthened stack-based problem solving Learning one problem every single day 🚀 #Java #LeetCode #DSA #Stack #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
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