Ruby solution O(n)


#1

Copy values to array.
Shift array.
Copy values back to list.

def rotateRight(a, b)
    return if a.nil?
    
    head = a
    arr  = []
    ind  = 0
    
    while !head.next.nil? do
        arr[ind] = head.data
        ind     += 1
        head     = head.next
    end
    
    arr[ind]  = head.data
    size      = arr.size
    head      = a
    b         = b % size
    
    first_part_arr  = arr[0..size - b]
    second_part_arr = arr[size - b...size]
    shifted_arr     = second_part_arr + first_part_arr
    
    for i in (0...size) do
        head.data = shifted_arr[i]
        head      = head.next
    end
    
    return a
end