Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Count the number of characters <code>'c'</code> in string <code>s</code>, let’s call it <code>m</code>.
We can select <code>2</code> numbers <code>i</code> and <code>j</code> such that <code>i <= j</code> are the start and end indices of substring. Note that <code>i</code> and <code>j</code> can be the same.
The answer is <code>m * (m + 1) / 2</code>.