You are viewing a single comment's thread. Return to all comments →
the index range is inclusive of the start and end indices: [0, 1, 2].
we are looking at the set of chocolates from i to i+m and determining if that set meets our criteria. if it does, we increment total. then we increment i and look at the next set, and so on until we have traversed the array.
i like victorz's analogy below: it is a "sliding window."
i hope that helps.
For the same program, how can we get the result if the required chocolate squares are not consecutive?
thats not what the problem states ( these types of problem are called maximum-sub array problems ) ,
Still you want to solve this problem, you need to use Combinations, which will increase the diffuculty.
what is the i < n-m?