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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Arrays: Left Rotation
  2. Discussions

Arrays: Left Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

    You are viewing a single comment's thread. Return to all comments →

  • giri_manian
    2 months ago+ 0 comments

    Below is code i have submitted code using Java8

    public static List<Integer> rotLeft(List<Integer> a, int d) {
        int length = a.size();
        if (length < 2) {
            return a;
        }        
        Integer[] rotatedArray= new Integer[length];
        for(int i=0;i<length;i++){
            int target_index = (length - d + i);
            if (target_index > length - 1) {
                target_index = i - d;
            }
            rotatedArray[target_index] = a.get(i);
        }
        return Arrays.asList(rotatedArray);
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy