Getting TLE in the question

answer: https://ide.codingblocks.com/s/300257
question : https://hack.codingblocks.com/app/practice/3/542/problem

since max value of q is 10^6 and max value of r is 10^6 since, u are using a for loop in query loop the time complexity is 10^12. That is why, giving tle. Try to solve this problem using Binary Index Tree.

Create a Binary index tree of size 26 for each character and then store frequencies of different characters of string in it. Then at the end answer the queries in range l to r in O(logn) time.