Input: arr[] = {1, 2, 3, 4, 5}, K = 5
Output: 5
Explanation:
Initially, the array is {1, 2, 3, 4, 5}. Following operations are performed K(= 5) number of times:
After the 1st operation, the array modifies to {2, 3, 4, 5, 1, 1}.
After the 2nd operation, the array modifies to {3, 4, 5, 1, 1, 2, 2}.
After the 3rd operation, the array modifies to {4, 5, 1, 1, 2, 2, 3, 3}.
After the 4th operation, the array modifies to {5, 1, 1, 2, 2, 3, 3, 4, 4}.
After the 5th operation, the array modifies to {1, 1, 2, 2, 3, 3, 4, 4, 5, 5}.
After completing the above operations, the last element is 5. Therefore, the answer is 5.
Input: arr[] = {1, 2, 3}, K = 7
Output: 2
Consider an array arr[] = {1, 2, 3, 4, 5}
After first 5 operations, the array modifies to {1, 1, 2, 2, 3, 3, 4, 4, 5, 5}.
After first 10 operations, the array modifies to {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}.
Therefore, the size of the array after N * 2K operations is 2 * N * 2K.