code: def rotate_array_2(arr, k, right=True):
      n = len(arr)
      right %= n
  
      # going right for K places is same like going left for N-K places
      if not right:
          k = n - k
  
      # different sets
      sets = gcd(n, k)
      # elements in each set
      elements = n // sets
      i = 0
  
      while i < sets:
          j = 1
          curr = arr[i]
  
          while j <= elements:
              idx = (i + j * k) % n
              j += 1
  
              # add the previous element on this position
              curr, arr[idx] = arr[idx], curr
              """same as
              temp = curr
              curr = arr[idx]
              arr[idx] = temp
              """
  
          i += 1
  
      return arr
  
label_desc: Use image node_id 2 for calling a global function with example usage: rotate_array_2(arr, k, right) and returns: arr