CyclicRotation:Rotate an array to the right by a given number of steps.

An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place).
The goal is to rotate array A K times; that is, each element of A will be shifted to the right K times.
 //Code in Java
class Solution { public int[] solution(int[] A, int K) { int [] B =new int [A.length]; for(int i=0;i<A.length;i++) { int l= A.length; int pos=(i+K)%l; B[pos]=A[i]; } return B; } }

Comments

  1. Casino News, Reviews & Facts for Las Vegas
    The Vegas area 광주 출장샵 is home to a 경주 출장마사지 variety of gambling games and a thriving gambling community in the 영천 출장마사지 city. As 경기도 출장샵 a 광명 출장샵 result, there are several poker rooms,

    ReplyDelete

Post a Comment

Popular posts from this blog

Configure IP address on Oracle Linux

Oracle Directory Object