What’s the complexity of this solution?
Problem: Problem - B2 - Codeforces
I can see O(n)
but gives TLE on test case 18
What’s the complexity of this solution?
Problem: Problem - B2 - Codeforces
I can see O(n)
but gives TLE on test case 18
Your time comp is O(t*(n+k+d)).
So ,it is getting TLE.
For tc 18 t=1000 k=1000000
How can I improve on this, editorial says to use two pointers technique but that won’t get any better i guess ?..my complexity is actually O(t*(2n)) as k+d =n.
Take set and insert values till d. Now add 1 element and remove the last element and check size of set. You have to find min size.
Time comp is O(tnlogn)
It is guaranteed that the sum of the values of n for all test cases in the input does not exceed 2⋅10^5.
So, this will be fine