I want to find the occurrences of a character in a string for n queries: For example the string is: "i_love_mathematics" and the task is to find the occurrence of:
'i' in range:
1-4(a substring starting from 1st character and ending at 4th)
2-5
3-10
'_' in range:
1-10
3-9
The output would be:
1
0
0
2
1
The similar question was to find the number of occurrences of a character in a string but the complexity for that was O(N) but in this case, if I do that it would result in very high complexity, is there a data structure that could be used to solve this problem?