CyclicRotation My 100% Solution in Javascript
Question
My Solution
function solution(A, K) { K = K%A.length; if (K === 0) return A; let AA = A.concat(A); return AA.slice(A.length-K, A.length-K+A.length); }
Note
- The rotation of string A is a substring of AA
(since A = xy, AA = xyxy and any rotation of A is yx) - Notice the rotation direction