Interview problem--> Form a lexographically smallest string by using rotate and add operations.

Revision en4, by 444iq, 2019-09-15 03:59:28

You are given a string S which consists of digits from 0 to 9 and two integer R and A. There are two operations which you can do on a string.


You can use Rotate operation to rotate a string clockwise by R positions. For example if R=1 , string "581" will become "158" . Also you can use Add operation to add number A to all odd indexes of string ( 0 based indexing). For example if A=3 , then string "781" will become "711". Digits post 9 are cycled back to zero.

You can use any of the two operation any number of times in any order to return the lexicographical smallest string.


0<N<10 length of string



For example




Result: "11"

rotate it by 1, it becomes 13 and 4 two times to 3 it will be 11.

How to solve.


  Rev. Lang. By When Δ Comment
en4 English 444iq 2019-09-15 03:59:28 15 Tiny change: 'w to solve this problem? \n\n\n\n' -> 'w to solve. \n\n\n\n'
en3 English 444iq 2019-09-15 03:56:48 21
en2 English 444iq 2019-09-15 03:56:22 42
en1 English 444iq 2019-09-15 03:55:36 906 Initial revision (published)