the question on leetcode says "Given an array, rotate the array to the right by k steps, where k is non-negative." for example "Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4]"
My solution in python was:
def rotate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: None Do not return anything, modify nums in-place instead.
"""
i = 0
while (i < k):
nums.insert(0, nums.pop())
i+=1
This does not seem to match any of the given solutions. I am curious what the time/space complexity of this would be? Is that why this is not a given solution? OR is it best to not use array functions in tech interviews?
Thanks