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 →

  • ananth_adhikarla
    2 months ago+ 0 comments
    My solution i think its easy to use and implement not sure if its efficient though.
    
    public static List<Integer> rotLeft(List<Integer> a, int d) {
            // Loop from 0 to Number of rotations
            for(int i = 0; i < d ; i++)
            {
                    // Get the value at first index of list to temp variable
                    int temp = a.get(0);
                    // remove the first element
                    a.remove(0);
                    // add it back to list by default it goes to the end
                    a.add(temp);
            }
            return a;
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy