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

Max Contiguous Subarray

Given a list of integers, write a program to identify the contiguous sub-list that has the largest sum and print the sum. Any non-empty slice of the list with step size 1 can be considered as a contiguous sub-list.Input


The input will contain space-separated integers, denoting the elements of the list.Output


The output should be an integer.Explanation


For example, if the given list is [2, -4, 5, -1, 2, -3], then all the possible contiguous sub-lists will be,

[2]
[2, -4]
[2, -4, 5]
[2, -4, 5, -1]
[2, -4, 5, -1, 2]
[2, -4, 5, -1, 2, -3]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[-4, 5, -1, 2, -3]
[5]
[5, -1]
[5, -1, 2]
[5, -1, 2, -3]
[-1]
[-1, 2]
[-1, 2, -3]
[2]
[2, -3]
[-3]

Among the above contiguous sub-lists, the contiguous sub-list [5, -1, 2] has the largest sum which is 6.

Sample Input 1

2 -4 5 -1 2 -3

Sample Output 1

6




Interleave Strings

Given two strings, write a program to merge the given two strings by adding characters in alternating order, starting with the first string. If a string is longer than the other, append the additional characters onto the end of the merged string.Input


The first line of input will contain a string.

The second line of input will contain a string.

The strings may contain special characters, digits and letters.Output


The output should be the merged stringExplanation


For example, if the given strings are "abc" and "pqrs", then alternating characters from each string are merged as "a" from "abc", "p" from "pqr", "b" from "abc" and so on ..., resulting in the merged string "apbqcr".

Sample Input 1

abc

pqr

Sample Output 1

apbqcr

Sample Input 2

abc

pqrst

Sample Output 2

apbqcrst




Add two polynomials

Given two polynomials A and B, write a program that adds the given two polynomials A and B.


Sample Input

4

0 5

1 0

2 10

3 6

3

0 1

1 2

2 4

Sample Output

6x^3 + 14x^2 + 2x + 6


Sample Input

5

0 -2

3 6

4 7

1 -3

2 -1

5

0 1

1 2

2 -4

3 3

4 5

Sample Output

12x^4 + 9x^3 - 5x^2 - x - 1



Sample Input

5

0 2

1 0

2 1

4 7

3 6

5

2 4

3 3

4 5

0 1

1 0

Sample Output

12x^4 + 9x^3 + 5x^2 + 3


Add two polynomials

Given two polynomials A and B, write a program that adds the given two polynomials A and B.


Sample Input

4

0 5

1 0

2 10

3 6

3

0 1

1 2

2 4

Sample Output

6x^3 + 14x^2 + 2x + 6


Sample input

4

0 5

1 0

2 10

3 6

4

0 -5

1 0

2 -10

3 -6

Sample Output

Should be Zero: 0


Sample Input

5

0 2

1 0

2 1

4 7

3 6

5

2 4

3 3

4 5

0 1

1 0

Sample Output

12x^4 + 9x^3 + 5x^2 + 3


Add two polynomials

Given two polynomials A and B, write a program that adds the given two polynomials A and B.


Sample Input

4

0 5

1 0

2 10

3 6

3

0 1

1 2

2 4

Sample Output

6x^3 + 14x^2 + 2x + 6


Sample input

4

0 5

1 0

2 10

3 6

4

0 -5

1 0

2 -10

3 -6

Sample Output



Sample Input

5

0 2

1 0

2 1

4 7

3 6

5

2 4

3 3

4 5

0 1

1 0

Sample Output

12x^4 + 9x^3 + 5x^2 + 3


Add two polynomials

Given two polynomials A and B, write a program that adds the given two polynomials A and B.


Sample Input

4

0 5

1 0

2 10

3 6

3

0 1

1 2

2 4

Sample Output

6x^3 + 14x^2 + 2x + 6


Sample input

4

0 5

1 0

2 10

3 6

4

0 -5

1 0

2 -10

3 -6

Sample Output



Sample Input

5

0 2

1 0

2 1

4 7

3 6

5

2 4

3 3

4 5

0 1

1 0

Sample Output

12x^4 + 9x^3 + 5x^2 + 3


IPL Match Details

Write a program that reads all the match outcomes and summarizes the information of all the matches.

Points are given to the teams based on the outcome of the match.

A win earns a team 3 points. A draw earns 1. A loss earns 0.

The following information is expected:

MP: Matches Played

W: Matches Won

D: Matches Drawn (Tied)

L: Matches Lost

P: Points


The team information should be displayed in descending order of points.Inpu


Names of teams may contain spaces but will be less than 24 characters

100 >= N >= 0

Sample Input

6

CSK;RR;loss

RR;DD;draw

MI;KKR;win

KKR;RR;loss

CSK;DD;draw

MI;DD;draw

Sample Output

Team: RR, Matches Played: 3, Won: 2, Lost: 0, Draw: 1, Points: 7

Team: MI, Matches Played: 2, Won: 1, Lost: 0, Draw: 1, Points: 4

Team: DD, Matches Played: 3, Won: 0, Lost: 0, Draw: 3, Points: 3

Team: CSK, Matches Played: 2, Won: 0, Lost: 1, Draw: 1, Points: 1

Team: KKR, Matches Played: 2, Won: 0, Lost: 2, Draw: 0, Points: 0




Numbers in String - 1

Given a string, write a program to return the sum and average of the digits of all numbers that appear in the string, ignoring all other characters.Input


The input will be a single line containing a string.Output


The output should contain the sum and average of the digits of all numbers that appear in the string.

Note: Round the average value to two decimal places.Explanation


For example, if the given string is "I am 25 years and 10 months old", the digits of all numbers that appear in the string are 2, 5, 1, 0. Your code should print the sum of all digits(8) and the average of all digits(2.0) in the new line.

Sample Input 1

I am 25 years and 10 months old

Sample Output 1

8

2.0

Sample Input 2

Tech Foundation 35567

Sample Output 2

26

5.2




First Perfect Square

Given two integers (M and N), write a program to print the first perfect square in a given range.Input


The first line of input will contain a positive integer (M).

The second line of input will contain a positive integer (N).Output


The output should be a single line containing the first perfect square in a given range.Explanation


For example, if the given numbers are M is 4 and N is 16, the perfect squares from 4 to 16 are 4(2 * 2), 9(3 * 3), and 16(4 * 4), as the first perfect square is 4. So the output should be 4.

Sample Input 1

4

16

Sample Output 1

4

Sample Input 2

5

8

Sample Output 2

No Perfect Square




Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order.


The first line of input will contain two space-separated integers, denoting the M and N.

The next M following lines will contain N space-separated integers, denoting the elements of each list.


The output should be M lines containing the ordered matrix.

Note: There is a space at the end of each line.Explanation


For example, if the given M is 3 and N is 3, read the inputs in the next three lines if the numbers given in the next three lines are the following.

1 20 3
30 10 2
5 11 15


By ordering all the elements of the matrix in increasing order, the ordered matrix should be

1 2 3
5 10 11
15 20 30
LATEST TUTORIALS
APPROVED BY CLIENTS