1. You are given a 2D matrix a of dimensions MxN and a positive integer R.
Write
a program to rotate the matrix R times in anti-clockwise direction.
Rotation of a 4x5 matrix is represented by the following figure. Note that in one
rotation, you have to shift elements by one step only (refer sample tests for more
clarity).
It is guaranteed that the minimum of M and N will be even.
Input
First line contains three space separated integers, M, N and R, where M is the
number of rows, N is number of columns in matrix, and R is the number of times
the matrix has to be rotated.
Then M lines follow, where each line contains N space separated positive integers.
These M lines represent the matrix.
Output
Print the rotated matrix.
Constraints
2 <= M, N <= 300
1 <= R <= 10 9
1 <= a <= 10 , where i ∈ [1..M] & j ∈ [1..N]
min(M, N) % 2 == 0
8
ij
Sample Input
441
1234
5678
9 10 11 12
13 14 15 16
Sample Output
2348
1 7 11 12
5 6 10 16
9 13 14 15
2. Given an unsorted array with positive and negative numbers, find the
smallest missing positive number
3. Given an array representing a permutation, find the next lexicographically
greater permutation, or the lowest if none exists
4. Given an array of n elements, perform the minimum number of operations
where in each operation you can increment all elements except one to make
all elements equal
5. Given an array arr[] and an integer k, reverse every subarray of size k in-
place
6. Rearrange the array arr[] so that positive and negative numbers alternate,
starting with a positive number. Maintain relative order.
7. Given an integer array arr[] and a value element, write a program to
remove all occurrences of element in-place and return the count of remaining
elements
8. Write a program that accepts a matrix of integers from the user and calculates
the frequency of even numbers present in the matrix. The program should iterate
through all elements of the matrix, count how many of them are even, and display
the result
9. Write a program to update every element in an array with the
multiplication of its previous and next elements (assume the first and last
remain unchanged).
10. Write a program to sort n numbers where each number is in the range from 0 to
n².
11. Write a program to find the row with the maximum number of 1s in a binary
matrix.
12. For a given number, scan its digits from right to left — if two consecutive
digits are same, break the loop and print the pair
13. Keep dividing a number by the sum of its digits (if possible) until it is no
longer divisible — count the steps
14. Continuously accept numbers from the user, add them to a cumulative sum,
and stop only when the sum becomes prime
15. Take a number, reverse it, add it to the original — repeat the process until the
sum is a palindrome or a limit of 5 iterations is reached