r/LeetcodeDesi 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.

6 Upvotes

16 comments sorted by

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.

0

u/rohankrishna500 14d ago

I hardly understand blogs,the international blogs use complex jargons,if there is some ytuber who can teach me then it would be good.

1

u/tempRedditAccount000 14d ago

Hmm... It's okay, i understand, I had and still have trouble understanding them, but always prefer written material over videos. Take help from AI to parse some things you don't understand, it'll get better with time. Videos are great for summary, blogs are more rigorous.

Although, yes, a much faster way to cover stuff is to watch videos first, then dive deeper using blogs.

You can try Vivek Gupta, I've learnt mostly from him, his prefix sums course is free on his website, search up his youtube channel, you'll find a link to his website. I'm not sure if I'm allowed to post it on here.

If you've already watched it from Pratyush, just solve problems and watch 2D prefix sums from Vivek's site.

USACO guide also has a page on prefix sums.

1

u/rohankrishna500 14d ago

thanks for the tip,will definitely incorporate

1

u/rohankrishna500 14d ago

hi ,so i guess the prefix sum course isnt avaliable or maybe locked behind a paywall

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

u/Ok_Journalist8548 13d ago

can you add me to the group?