You calculated k as,
You could have done,
If you still face any problem,
Here’s the link to my code.
@shawnfrost thanks for answering this buddy but dude can you tell me why is k=r-(n-(j+1)); wrong.
It is obvious that the minimum value of j will be 2 i.e. String would be 111…so on,
so,we have k=r+3-n;
Given that,1 ≤ r ≤n implies 4-n ≤ k ≤ 3
and it’s wrong as you know, 1 ≤ k ≤ n.