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 →

  • amshay63
    3 months ago+ 1 comment

    If anyone has suggestions on how to improve this, please let me know! I'm doing my best to learn how to become an efficient programmer.

    vector<int> rotLeft(vector<int> a, int d) {
        vector<int> a2(a.size());
        for (int i = 0; i < a2.size(); i++, d++) {
            if (d == a2.size()) {
                d = 0;
            }
            a2[i] = a[d];
        }
        return a2;
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy