Optimize Performance challenge 'Vinay Queried '
Target string could be 5000 digits strong. It means that the target_subsets can have up to 12500000 elements. It is huge (I am surprised that the memory limit was not exceeded). You scan all of them for each query. Time limit exceeded obviously.

One obvious improvement is to sort target_subsets, and look for a lower bound of a query value (in logarithmic time). The result is simply len(target_subsets) - lower_bound.

This is still suboptimal, because the way you compute target_subsets has \$O(N^3)\$ time complexity. It is another candidate for TLE. It is more or less trivial to reduce it to \$(N^2)\$, but I'd still be uncomfortable.

The solution is a simple linear scan, along the lines of

Let `d` be a first non-zero digit of a query string
For target digit 't' at index 'i'
    if t &gt; d, there are `len(target_string) - len(query) - i` pairs (as long as it is positive);
    if t == d, there _may_ produce one extra pair;
    it 0 &lt; t &lt; d, there are `len(target_string) - len(query) - i - 1` pairs (again, as long as it is positive);
    if t == 0, there are as many pairs as for the next non-zero digit.