333iq's blog

By 333iq, history, 5 weeks ago, ,

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.

Rotate
Add

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.

Constraints

0<N<10 length of string

0<=A<100

1<=R<=N

For example

S="31"

R=1

A=4

Result: "11"

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

How to solve.

• -2

 » 5 weeks ago, # |   0 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.
•  » » 5 weeks ago, # ^ |   0 Thanks a lot. It worked :)