educative.io

Is anything wrong with solution when printing gives same output as expected output

def rotate_array(nums, n):

  #TODO: Write - Your - Code  sizee = len(nums)

  sizee = len(nums)

  temp_lst = []

  temp_lst = nums[:sizee-n]

  print('pre altered temp list is ', temp_lst)

  for i in range(n):

    temp_lst.insert(i,nums[sizee-n+i])

  print("temp list is ", temp_lst)

  nums = temp_lst  

  print("nums is ", nums)

  return temp_lst

i was checking the console output and i have same as expected output (in case n > 0) , but platform is mentioning that test cases failed. Is there anything apparently wrong ?


Course: Coderust: Hacking the Coding Interview - Learn Interactively
Lesson: https://www.educative.io/courses/coderust-hacking-the-coding-interview/rotate-an-array-by-n-elements


Course: https://www.educative.io/courses/coderust-hacking-the-coding-interview
Lesson: https://www.educative.io/courses/coderust-hacking-the-coding-interview/rotate-an-array-by-n-elements

Hi @Osama_Naeem,
In terms of the logic of your solution for the case where n>0, it seems to be fine. The only trouble is with returning the changed nums array, versus simply changing it in place. We’re looking into this in more detail and will get back to you in a couple of days.
Thanks!