444iq's blog

By 444iq, history, 7 months ago, In English,

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.

  • Vote: I like it
  • -2
  • Vote: I do not like it

7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Easy one, push rotates and adds into the queue. do a bfs on the queue. keep map to trace repeated strings. push all the generated unique strings to vector, sort the vector, cout << v[0] will be the answer. try this once.