0% found this document useful (0 votes)
7 views7 pages

Coding

The document contains multiple programming tasks including rotating a 2D array by 90 degrees clockwise, reversing each word in a string, identifying Kaprekar numbers, generating a specific series, and finding the common ancestor in a binary search tree. Each task is presented with sample inputs and outputs to illustrate the expected results. The tasks cover various aspects of programming and algorithm implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Coding

The document contains multiple programming tasks including rotating a 2D array by 90 degrees clockwise, reversing each word in a string, identifying Kaprekar numbers, generating a specific series, and finding the common ancestor in a binary search tree. Each task is presented with sample inputs and outputs to illustrate the expected results. The tasks cover various aspects of programming and algorithm implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SOLUTION:

n=4

curr = 1

maxi = n * (n + 1)

for i in range(n):

print('-' * (i * 2), end='')

for j in range(n - i):

print(curr, end='')

if j != n - i - 1:

print('*', end='')

curr += 1

for j in range(n - i-1,-1,-1):

print('*', end='')

print(maxi - j, end='')

maxi -= (n - i)

print()
Mr. Bean has saved an image in a 2D array and he wants to rotate the image by 90 degrees in
clockwise direction. Please help him code for array rotation by 90 degrees in clockwise direction.

Sample Input 0
3
123
456
789
Sample Output 0
741
852
963
Sample Input 1
3
-5 -10 -4
3 -6 3
-1 0 -6
Sample Output 1
-1 3 -5
0 -6 -10
-6 3 -4

Write the program to reverse each word of a string.


Input Format
Input consists of one string Constraints NA
Output Format
The output consists of one string (reverse of the input string)
Sample Input 0 Hello World Sample Output 0 World Hello
Sample Input 1 welcome to face Sample Output 1 face to welcome

Jaffer wanted to excel in Math. He was learning about the Kaprekar number from Meena, his Maths
teacher. She gave him a few random numbers and asked him to find out whether they are Kaprekar
number or not. (Consider an n-digit number k. Square it and add the right n digits to the left n or n-1
digits. If the resultant sum is k, then k is called a Kaprekar number. For example, 9 is a Kaprekar
number since 9^2 = 81 & 8 + 1 = 9, similarly, 297 is a Kaprekar number as 297^2 = 88209 & 88 + 209
= 297

Sample Input 0

45

Sample Output 0

Kaprekar Number

Sample Input 1

23

Sample Output 1

Not a Kaprekar Number

Write a program to generate the following series 0,2,8,14,...,34.

Input Format

The input is an integer that denotes 'n'.

Output Format

Print the series and refer to the sample output for formatting.

Sample Input 0

10

Sample Output 0

0 2 8 14 24 34 48 62 80 98

Sample Input 1

Sample Output 1 0 2 8 14
An infinite line of integer input representing the nodes of the binary search tree. If any value less than
1 is encountered, the input loop has to break and print the common ancestor for the given nodes in
the tree.

Example Input

2 3 1 -1 3 1

Output

2 Explanation 2 is the root and 3 and 1 are the children of 2.

You might also like