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 - CodeChef: Practical coding for everyone

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ā€¦_
If you cant understand let me know will explain you