Rotate Array
Leetcode - 189 Rotate Array Problem: https://leetcode.com/problems/rotate-array/ The given problem expects the given array to be rotated to the right by k steps. For example, given [1, 2, 3, 4, 5, 6] and k = 3, we need to perform the following: and hence we get the array, [4, 5, 6, 1, 2, 3] We can generalize the problem as following: Given an array of n-elements, perform m-rotations by magnitudes r[0], r[1], ...., r[m-1] given as array r, either by left or right given by array d[0], d[1], d[2], ...., d[m-1]. If d[i] = 0, then rotate left or rotate right otherwise. We try solving this version of the problem. Finally we reduce the generalized problem into the original problem. Solution 1: Bruteforce - O(mn) time, O(1