We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I liked your approach.But I would like to pin point one thing here as you have been already given an array and N number of rotation.ON that array you have to perform operations.You are changing it while reading from console.
please have a look at this and let me know if this can be optimized.
static int[] leftRotation(int[] a, int d) {
// Complete this function
int[] b= new int[a.length];
for(int iLoop=0;iLoop<a.length;iLoop++){
b[iLoop]=a[iLoop];
}
for(int iLoop=0;iLoop<a.length;iLoop++){
a[iLoop]=b[(iLoop+d)%a.length];
}
return a;
}
But Really good solution though.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
I liked your approach.But I would like to pin point one thing here as you have been already given an array and N number of rotation.ON that array you have to perform operations.You are changing it while reading from console. please have a look at this and let me know if this can be optimized.
static int[] leftRotation(int[] a, int d) { // Complete this function