#K66052. Right Rotation of a String
Right Rotation of a String
Right Rotation of a String
Given a string s
and an integer k
, perform a right rotation on the string by k
positions. In other words, move the last k
characters of the string to the beginning. The rotation is defined mathematically as follows:
If k
is greater than the length of the string, you should rotate the string by k \mod n
positions, where n
is the length of the string. Handle edge cases such as an empty string or a single-character string appropriately.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains an integer
k
, representing the number of positions to rotate to the right.
outputFormat
Output the rotated string as a single line.
## samplehello
2
lohel