Rotate Matrix Rings
Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.
Input
The first line of input will be two space-separated integers, denoting the M and N.
The next M lines will contain N space-separated integers.
The next line will contain an integer, denoting K.
Output
The output should be M*N matrix by rotating the matrix by K elements.
Explanation
Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So the output should be
4 8 12 16
3 10 6 15
2 7 11 14
1 5 9 13
Sample Input 1
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4
Sample Input 2
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Sample Output 2
9 10 1 2
8 11 12 3
7 6 5 4
Vertical Printing
You are given a string(S) with multiple words in it. Return all the words vertically in the same order in which they appear in S.
Complete with spaces when it is necessary while forming the words vertically. (Trailing spaces are not allowed).
Note: All characters in S are upper case.
Input
The first line contains a string S.
Output
Each line of the output contains a string formed vertically as mentioned above.
Explanation
Given S = CAT BAT VIN.
We are expected to print the words vertically such that considering the ith letter in each line of the output will form the ith word in the given input.
Printing the given words vertically
Joining all the first characters from the 3 lines of output gives CAT.
Joining all the second characters from the 3 lines of output gives BAT.
Joining all the third characters from the 3 lines of output gives VIN.
Sample Input 1
CAT BAT VIN
Sample Output 1
CBV
AAI
TTN
Sample Input 2
MAM BY DORM
Sample Output 2
MBD
AYO
M R
M
Smaller Scores
A group of people(P) are playing an online game. Their scores are stored in the order of their entry time in S. Each integer S[i] corresponds to the score of the person Pi.
For each person Pi you have to report the number of people who played after the person and scored less than the person.
Input
The first line contains a single integer N.
The second line contains N space-separated
Output
The output should contain N space-separated integers representing the number of people who played after the person and scored less than the person.
Explanation
Given S = 13 12 11
Score of P1 is 13.
Score of P2 is 12.
Score of P3 is 11.
The number of people who played after P1 and scored less than 13 is 2(12, 11).
The number of people who played after P2 and scored less than 12 is 1(11).
The number of people who played after P3 and scored less than 11 is 0.
The output is 2 1 0.
Sample Input 1
3
13 12 11
Sample Output 1
2 1 0
Sample Input 2
4
4 3 5 2
Sample Output 2
2 1 1 0
Largest Missing Negative Number
You are given an unsorted array A of N integers. You have to find
the largest negative integer missing from the array.
Input
The first line contains N space-separated integers of A
Output
The output contains N space-separated integers representing the number of people as mentioned above.
Explanation
Given A-2-1012
The largest negative number missing is 3
Sample Input 1
-2 -1 0 1 2
Sample output 2
-3
sample input 2
-11 -10 -12
Sample output 2
-1
Largest Missing Negative Number
You are given an unsorted array
The first line contains
The output contains
Given
A = -2 -1 0 1 2.The largest negative number missing is
-3.
Sample Input 1
-2 -1 0 1 2
Sample Output 1
-3
Vertical Printing
You are given a string(
S) with multiple words in it. Return all the words vertically in the same order in which they appear in S.Complete with spaces when it is necessary while forming the words vertically. (Trailing spaces are not allowed).
Note: All characters in
The first line contains a string
Each line of the output contains a string formed vertically as mentioned above.
Given
S = CAT BAT VIN.We are expected to print the words vertically such that considering the
ith letter in each line of the output will form the ith word in the given input.Printing the given words vertically
CBV
AAI
TTN
Joining all the first characters from the 3 lines of output gives
CAT. Joining all the second characters from the 3 lines of output gives BAT. Joining all the third characters from the 3 lines of output gives VIN.
Sample Input 1
CAT BAT VIN
Sample Output 1
CBV
AAI
TTN
Smaller Scores
A group of people(
P) are playing an online game. Their scores are stored in the order of their entry time in S. Each integer S[i] corresponds to the score of the person Pi.For each person
The first line contains a single integer
The output should contain
Given
S = 13 12 11Score of
P1 is 13. Score of P2 is 12. Score of P3 is 11.The number of people who played after
P1 and scored less than 13 is 2(12, 11). The number of people who played after P2 and scored less than 12 is 1(11). The number of people who played after P3 and scored less than 11 is 0.
The output is
2 1 0.
Sample Input 1
3
13 12 11
Sample Output 1
2 1 0
You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
Input
The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.
Design a recursive function that accepts an integer argument, n, and prints every second number from n down to a minimum of 0. Assume that n is always a positive integer.
Given the line
y= 3x+ 15
, and the points a = (1,0) and b= (9,0), which point
has the smallest squared error from the line?