Questions: 5 831

Answers by our Experts: 5 728

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Maximum

You are given

N number of inputs. Print the maximum of them after each input.Input

The first line of input is an integer

N. The next N lines each contain an integer as input.Explanation

In the example, you are given

6 inputs 1, 0, 3, 2, 9, 8.

1 is maximum in the input 1.

1 is maximum in the input 1, 0.

3 is maximum in the input 1, 0, 3.

3 is maximum in the input 1, 0, 3, 2.

9 is maximum in the input 1, 0, 3, 2, 9.

9 is maximum in the input 1, 0, 3, 2, 9, 8.

 


So, the output should be


1

3

3

9

9




Last half of List

You are given an integer 

N as input. Write a program to read N inputs and print a list containing the elements in the last half of the list.

Input

The first line of input is an integer 

N. The second line contains N space-separated integers.

Explanation
Sample Output 1

In the example, we are given 

6 numbers 1, 2, 3, 4, 5, 6 as input.

The last half of elements of the list are 

4, 5, 6. So, the output should be [4, 5, 6].

Sample Output 2

In the example, we are given 

5 numbers 1, 11, 13, 21, 19 as input. The last half of elements of the list are 21, 19. So, the output should be [21, 19].

Sample Input 1
6
1 2 3 4 5 6
Sample Output 1
[4, 5, 6]
Sample Input 2
5
1 11 13 21 19
Sample Output 2
[21, 19]

List Indexing - 3

Given 

N numbers, and an index, write a program to store the numbers in a list and print the number at given index. For this problem, each input will contain T testcases. Each testcase will give an index Ki as input, which should be considered to print the number.

Input

The first line of input is an integer 

N. The second line of input is an integer T representing the number of testcases. The next N lines contain integers representing the numbers of the list. The next T lines contain integer Ki for each line.

Output

You need to print a number in a new line for each of the 

K testcases.

Explanation

In the given example, we are given 

4 numbers 1, 2, 3, 4 as input For the first testcase, K=0, the number at 0th index is 1. For the second testcase, K=3, the number at 3rd index is 4. So, the output should be

1
4
Sample Input 1
4
2
1
2
3
4
0
3
Sample Output 1
1
4
Sample Input 2
3
1
13
21
19
0
Sample Output 2
13

Shaded Diamond

Given an integer value 

N as input, write a program to print a shaded diamond of 2*N -1 rows using an asterisk(*) character as shown below.

Note: There is a space after each asterisk (*) character.

Input

The first line of input is an integer 

N.

Explanation

In the given example 

N = 5. Therefore, the output should be

    * 
   * * 
  * * * 
 * * * * 
* * * * * 
 *     *
  *   *
   * *
    *
Sample Input 1
6
Sample Output 1
     * 
    * * 
   * * * 
  * * * * 
 * * * * * 
* * * * * * 
 *       *
  *     *
   *   *
    * *
     *
Sample Input 2
5
Sample Output 2
    * 
   * * 
  * * * 
 * * * * 
* * * * * 
 *     *
  *   *
   * *
    *

Number Diamond

Given an integer 

N as input, write a program to print a number diamond of 2*N -1 rows as shown below.

Note: There is a space after each number.

Input

The first line of input is an integer 

N.

Explanation

In the given example, the number of rows in the diamond is 

5.

So, the output should be

    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1
Sample Input 1
5
Sample Output 1
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1
Sample Input 2
4
Sample Output 2
   1 
  1 2 
 1 2 3 
1 2 3 4 
 1 2 3 
  1 2 
   1

Half Pyramid - 3

Given an integer 

N as a starting number and K as input, write a program to print a number pyramid of K rows as shown below.

Input

The first line of input is an integer 

N. The second line of input is an integer K.

Explanation

In the example, the given starting number is 

10, and the number of rows in the pyramid is 5.

So, the output should be

10
11 12
13 14 15
16 17 18 19
20 21 22 23 24
Sample Input 1
10
5
Sample Output 1
10 
11 12 
13 14 15 
16 17 18 19 
20 21 22 23 24
Sample Input 2
1
3
Sample Output 2
1 
2 3 
4 5 6

In the given example, the first side

A = 3, and the second side B = 4. To calculate the hypotenuse we use Pythagoras theorem. According to Pythagoras theorem, hypotenuse2 = 32 + 42

Therefore, the hypotenuse value is

5. So, the output should be 5.


W pattern with *

Write a program to print 

W pattern of N lines using an asterisk(*) character as shown below.

Note: There is a space after each asterisk * character.

Input

The first line is an integer 

N.

Explanation

For 

N = 5

The output should be

* * * * * * * * * 
 * * * * * * * * 
  * * *   * * * 
   * *     * * 
    *       *
Sample Input 1
5
Sample Output 1
* * * * * * * * * 
 * * * * * * * * 
  * * *   * * * 
   * *     * * 
    *       *
Sample Input 2
4
Sample Output 2
* * * * * * * 
 * * * * * * 
  * *   * * 
   *     *

Armstrong numbers between two intervals

Write a program to print all the Armstrong numbers in the given range 

A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digits.

Input

The first line has an integer 

A. The second line has an integer B.

Output

Print all Armstrong numbers separated by a space.
If there are no Armstrong numbers in the given range, print 

-1.

Explanation

For 

A = 150 and B = 200

For example, if we take number 153, the sum of the cube of digits 

1, 5, 3 is

 13 + 53 + 33 = 153.

So, the output should be 

153.

Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3




Pyramid

Given an integer

N, write a program to print a pyramid of N rows as shown below.Input

The first line of input is an integer

N.Explanation

In the example, the number of rows in the pyramid is

5.So, the output should be

Sample Input 1
5
Sample Output 1
. . . . 0 . . . . 
. . . 0 0 0 . . . 
. . 0 0 0 0 0 . . 
. 0 0 0 0 0 0 0 . 
0 0 0 0 0 0 0 0 0
Sample Input 2
6
Sample Output 2
. . . . . 0 . . . . . 
. . . . 0 0 0 . . . . 
. . . 0 0 0 0 0 . . . 
. . 0 0 0 0 0 0 0 . . 
. 0 0 0 0 0 0 0 0 0 . 
0 0 0 0 0 0 0 0 0 0 0

LATEST TUTORIALS
APPROVED BY CLIENTS