• Rotate an array or linked listin_place.

Attempt 1

  • gyan_pelo
  • To rotate an array in place only two elements can be stored in the memory at a time, there will be only one extra variable, the new index of the element is going to be n + k, so if rotation has to be done by 2, then 0th index element will go at the 2nd index.
  • There can be one more way which is by extending the array size, not sure if this is required here so will skip it.
  • For the first approach the last elements are going to create issue.
  • Replacing one element at a time will also not work since more than one element will need to be stored at a time.

Attempt 2

gyan_pelo

  • This can be donein_place by reversing the arrays, after splitting based on minimum element. Then reverse the arrays, then combine both arrays and reverse them again.
  • How to reversein_place ?