You are viewing a single comment's thread. Return to all comments →
Java 8
Time complexity - O(n)
I calculate each item's new index after d rotations and add it to a new list.
public static List<Integer> rotLeft(List<Integer> a, int d) { // Write your code here // d<=n List<Integer> rusultList = new ArrayList<>(); for(int i=0; i<a.size(); i++) { rusultList.add(a.get((i+d) % a.size())); } return rusultList; }
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays: Left Rotation
You are viewing a single comment's thread. Return to all comments →
Java 8
Time complexity - O(n)
I calculate each item's new index after d rotations and add it to a new list.