Getting TLE in RAAVANCH problem!

i submitted a solution in java , but it was getting TLE !! :worried:
for me it was very confusing as i thought my solution’s time complexity is O(N) and as we must print the array so O(N) should be okay !!
so can someone please tell me why TLE occured and how to optimize the solution !?
link to my java solution - https://www.codechef.com/viewsolution/33159836

Use fast IO , even to optimize a little more w.r.t runtime u shoul use Stringbuilder.

1 Like

The best approach here will be printing the sequence of 0 and X. I mean if K is 3,N=7 and X=5 then print 0 0 5 0 0 5 0

1 Like

yeah , this was my approach ,but still got TLE!!

sorry I dont know java but why are you declaring array and doing all those stuffs…Here is my simple solution…_https://www.codechef.com/viewsolution/33158397
If you cant understand let me know will explain you