Sort by

recency

|

3565 Discussions

|

  • + 0 comments

    Simplest solution in Python!

    def rotateLeft(d, arr): for i in range(d): num = arr.pop(0) arr.append(num) return arr

  • + 0 comments

    Mi solución en Python 3:

    def rotateLeft(d, arr):
        # Write your code here
        n = len(arr)
        d = d%n
        return arr[d:] + arr[:d]
    
  • + 0 comments

    JavaScript

    while (d > 0) {
            let removed = arr.shift();
            arr.push(removed);
            d--;
    }
    return arr;
    
  • + 0 comments

    def rotateLeft(d, arr): return arr[d:]+arr[:d]

  • + 0 comments
    int size = arr.size();
    vector<int> newArr;
    for (int i = 0; i < size; i++) {
    		newArr.push_back(arr[(i + d) % size]);
    }
    return newArr;
    

    C++: Insert the values into a new array and use modulus operator to wrap around original array when iterating through