You are viewing a single comment's thread. Return to all comments →
public static List<Integer> rotateLeft(int d, List<Integer> arr) { List<Integer> results = new ArrayList<>(arr); for(int i=arr.size()-1;i>=0;i--){ int index = (i-d); if(index<0){ index = index+ arr.size(); results.set(index, arr.get(i)); } else { results.set(index, arr.get(i)); } } return results; } }
Left Rotation
You are viewing a single comment's thread. Return to all comments →