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
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.
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