Help need in a codeforces question

so here is the question

and here is my solution

my logic is that if there are 2 or more star in the string then my pointer goes to the first star then skips the max limit allowed ahead and then starts moving back as soon as it finds a star again it resets form that point and starts the whole process again

the time complexity should be O(n) but for some reason it is giving a TLE

Detail Analysis of your code

1>First of all value of n==50 , so there is no chance that you will get a TLE even if you write an exponential 2nd order solution also.

2>You are getting TLE because of an infinite loop .

3>Check the test case below and dry run this line on it
It will form an infinite loop . It will come back to the first star again and again after moving i+k distance.

while(curr_index < len){
                   while(str[curr_index] != '*'){
                       curr_index--;
                   }

1
7 3
.*....*

4>Here is my easy shortcode for the same logic you are thinking.

Any problem feel free to discuss.

really sry for the late reply…
but that test case wouldn’t be there as in the question it is given that the distance between adjacent * doesn’t exceed k