Hi LC community,
I have trouble with figuring out the correct indexing. For example, I want to sum the last K numbers starting from index i or I want to count the number of elements between index i and j, or count the number of sliding windows of width K. Without a careful thought, my index might be off by 1.
I have found that I usually spend like 3-10 minutes just to figure out the correct indexing. This struggle has occurred often when I worked on some DP problems.
Is there any tip or suggestion on how to deal with the indexing?
My bread-and-butter formula is:
Is there anything else you can share?
Thank you!