Sort by

recency

|

3493 Discussions

|

  • + 0 comments

    The most simpe solution I could think of

    Swift: func rotateLeft(d: Int, arr: [Int]) -> [Int] { let movedIdx = d % arr.count //get amount of index 0 shift return arr.dropFirst(movedIdx) + arr.dropLast(arr.count - movedIdx) }

  • + 0 comments

    Left rotation reminds me of efficient data handling—shifting elements seamlessly to maintain order. Similarly, data archiving ensures that large datasets are stored and retrieved effortlessly, keeping workflows smooth and efficient. It’s all about finding smart solutions to manage information effectively!

  • + 0 comments

    C++

    vector<int> rotateLeft(int d, vector<int> arr) {
        int size=arr.size();
        int i,j;
        i=0;
        for( i=0;i<d;i++){
            j=0;
            int temp=arr[j];
            for( j=0;j<size-1;j++){
                
                arr[j]=arr[j+1];
                
            }
            arr[j]=temp;
        }
        return arr;
    
    }
    
  • + 0 comments

    Here is my c++ solution, you can have the video explanation here : https://youtu.be/lyUDSB4Sg7Y

    vector<int> rotateLeft(int d, vector<int> arr) {
        int n = arr.size();
        vector<int> result(n);
        for(int i = 0; i < n; i++){
            int newIndex = (i - d + n) % n;
            result[newIndex] = arr[i];
        }
        return result;
    }
    
  • + 0 comments

    JS Solution

    let n = Math.ceil(d / arr.length) + 1;
    let tempArray = Array(n).fill(arr).flat();
    for (let index = 0; index < arr.length; index++) {
    	arr[index] = tempArray[index + d];
    }
    return arr;
    }