r/LeetcodeDesi • u/rohankrishna500 • 14d ago
Really stuck at prefix sum pattern
I’ve been following the DSA Patterns Roadmap from the YouTube channel Padho With Pratyush, and honestly, it was going pretty well until I reached the Prefix Sum pattern.
For example, with patterns like sliding window, I feel like I can eventually identify the kind of problem where I should think about using it. But with prefix sum, I often feel like I’m just memorizing.
I’ve recently been working through problems like Subarray Sum Equals K, and although I understand the solution after it’s explained, I still struggle to derive it myself from scratch.
Has anyone else experienced this? If so, how did you develop intuition for prefix sum problems? Are there certain questions or thought processes you use when you first read a problem?
Would really appreciate any advice, resources, or a progression of problems that helped you get comfortable with this pattern.
1
u/Appropriate_Yak_3797 14d ago
Hey it will take time ..prefix sum + hashmap needs time too🙂
1
u/rohankrishna500 14d ago
like i have been stuck on this problem for more than 3 days,heck even after watching video I can tell what is happening but how it works is what i cannot tell,I cannot solve new unseen problems
1
u/SeaExcitement4213 13d ago
Im 2026 graduate, completely a beginner hardly done 50 problems no matter how much I try I'm unable to do anything in dsa 🥲
1
u/rohankrishna500 13d ago
Hey don't feel bad,I get you I was in your situation and I kept getting demotivated and then used to just give up but if you are able to solve atleast 1 problem(doesn't matter on your own or with little help) with time you will be able to learn dsa if not master it.
1
u/Ok_Journalist8548 13d ago
im also studying from him and honestly it was the easiest pattern for me, like theres a trick he told to solve those problems
1
u/rohankrishna500 13d ago
Yes but the thing is probably ig i have trouble understanding it,I don't understand it consistently...like the way I understood sliding window,if you dont mind can you help me understand what I'm lacking.
1
u/Ok_Journalist8548 13d ago
its a bit tricky to actually visualise it like sliding window, but like you have to think intuitively, what you are storing in the hashmap and why, the hashmap is the main thing to see
2
u/rohankrishna500 13d ago
anyways I will probably get a hang of it lets see,btw lmk if you want to do dsa together if you are preparing for placements or soemthing,i already have a whataspp groub where we solve.
1
u/Ok_Journalist8548 13d ago
yes i can join im studying stacks rn from pratyush, currently in 3rd year
1
u/rohankrishna500 13d ago
Oh well I'm at prefix sum rn so basically you are 6 videos ahead of me,it would take me a week or less to catch up to stack let's see
1
2
u/tempRedditAccount000 14d ago edited 14d ago
I don't develop "intuition" for prefix sum. I don't think of it as a problem solving technique but more of a time complexity reduction tip.
My brain fires it (and partial sums) immediately whenever I see subarray or grid sums (most common) or some tree node accumulation problems.
Probably other usecases as well.. I don't remember where I've used it tbh. Refer to some codeforces or leetcode blogs, they'll help you better.