Given
N = 10From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.
So the output should be 9 + 2 =
11.
Sample Input 1
10
Sample Output 1
11
Sample Input 2
4
Sample Output
4
Write a program to print the anti-diagonal elements in the given matrix.
Input
The first line of input will contain an integer N, denoting the number of rows and columns of the input matrix.
The next N following lines will contain N space-separated integers, denoting the elements of each row of the matrix.
Output
The output should be a list containing the anti-diagonal elements.
Explanation
For example, if the given N is 3, and the given matrix is
1 2 3
4 5 6
7 8 9
The anti diagonal elements of the above matrix are 3, 5, 7. So the output should be the list
[3, 5, 7]
Sample Input 1
3
1 2 3
4 5 6
7 8 9
Sample Output 1
[3, 5, 7]
Sample Input 2
5
44 71 46 2 15
97 21 41 69 18
78 62 77 46 63
16 92 86 21 52
71 90 86 17 96
Sample Output 2
[15, 69, 77, 92, 71]
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]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[5]
[5, -1]
[5, -1, 2]
[-1]
[-1, 2]
[2]
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
Sample Input 2
-2 -3 4 -1 -2 1 5 -3
Sample Output 2
7
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]
[-4]
[-4, 5]
[-4, 5, -1]
[-4, 5, -1, 2]
[5]
[5, -1]
[5, -1, 2]
[-1]
[-1, 2]
[2]
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
Sample Input 2
-2 -3 4 -1 -2 1 5 -3
Sample Output 2
7
CS Python Fundamentals Assignment 1: Silly Sentences
Give a strategy for avoiding nested conditionals .