[HELP]What is the best approach to solve this problem ?

I am working on this problem. I want to know what should be the best approach to solve this problem. I am a newbie in algorithm designing so it would be great if its described in brief.



Take two strings

S1= “abcdefghijklmnopqrstuvwxyz”;
S2= “zyxwvutsrqponmlkjihgfedcba”;

Input K.
X= K/25. and Y=K%25.(remainder).

Yoc can print Y, Y-1, Y-2…0th character of S2 first.

Then Print whole S1 string X times.


For K=26 the answer is bazyxwvutsrqponmlkjihgfedcba . Here string S2 will create 25 decreasing pairs and for the additional one pair you can output ba as extra characters. Since you need to find the smallest one then this will be the answer.

1 Like

You dont need to print S2 character wise. You need to print S2 total K/25 times times so when X=1 then whole S2 will print 1 time.

1 Like

Thanks , now I fully get it.