How can we solve the below question in best possible complexity?
Q: String array (arr) and a query array(Q[][]) are given. You need to return character at kth index after concatenating string from index 'i' till 'j' in arr and sorting it.
E.g:
arr[] = [aaaaa,
bbbbb,
ccccc,
ddddd,
eeeee]
Q[][] = [ 1 5 16
3 5 15 ]
Output:
d
e
Explanation: 1. resultant string after concatenating from 1 to 5 is aaaaabbbbbcccccdddddeeeee and 16th index is 'd'
2. resultant string after concatenation from 3 to 5 and sorting is cccccdddddeeeee and 15th index is 'e'.
I tried with below steps:
But it is causing TLE.
Please help me to solve this in best time complexity to avoid TLE.