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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Arrays: Left Rotation
  2. Discussions

Arrays: Left Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

Sort 4818 Discussions, By:

recency

Please Login in order to post a comment

  • Mahendran_C
    20 hours ago+ 0 comments

    what went wrong with this code? function rotLeft(a, d) { // Write your code here

    let sArr = a.slice(0,d);
    let rArr = a.slice(d)
    let rotArr =rArr.concat(sArr)
    
    let str = "";
    rotArr.forEach(function(element){
        str += element + " ";
    })
        console.log(str)
    

    }

    0|
    Permalink
  • boyrazemre01
    4 days ago+ 0 comments

    C#

    	int item = 0;
            for (int i = 0; i < d; i++)
            {
                item = a[0];
                a.RemoveAt(0);
                a.Add(item);
            }
    
            return a;
    
    0|
    Permalink
  • ghalynho10
    4 days ago+ 0 comments

    JavaScript

    let newArr = a.slice(d)
    newArr = [...newArr,...a.slice(0,d)]
    return newArr
    
    0|
    Permalink
  • kayonbahenrique
    1 week ago+ 0 comments

    Javascript

     let arr1 = a.slice(0,d);
     let arr2 = a.slice(d, a.length);
     arr2.push(...arr1)
     
    return arr2
    
    0|
    Permalink
  • bootex
    2 weeks ago+ 0 comments

    C++

    vector<int> rotLeft(vector<int> a, int d) {
        vector<int> arr;
        int siz = a.size(), idx;
        for(int i = 0; i < siz; i++){
            idx = (i + d) % siz;
            arr.insert(arr.end(), a[idx]);
        }
        return arr;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy