Saturday 12 August 2017

Write a program in JAVA to left rotate of an array.

This is a common interview question in java. You will be given an array and a number(k) which needs to be rotated.
for example, consider we have an array rotate[]={1,2,3,4,5}; and given input no is: 3.
Output will be: rotate[]={4,5,1,2,3}.

Logic: we will take two arrays, i,e temp and finalArray. Temp array will contain only those elements  upto K. After that we will merge temp array to finalArray.




Output:

No comments:

Post a Comment