Arrays: Left Rotation

  • + 0 comments
        public static List<Integer> rotLeft(List<Integer> a, int d) {     
            List<Integer> rotations = new ArrayList<>();
            // Elements from index d to the end
            rotations.addAll(a.subList(d, a.size())); 
            // Elements from the start to index d
            rotations.addAll(a.subList(0, d)); 
            
            return rotations;
        }