Please scroll down for latest Programs 👇
1. Programming Assignment | Week 9
word is a string that contains one or more parentheses of the following types: "{ }", "[ ]", "( )". The string is said to be balanced if all the following conditions are satisfied.
When read from left to right:
(1) The number of opening parentheses of a given type is equal to the number of closing parentheses of the same type.
(2) An opening parenthesis cannot be immediately followed by a closing parenthesis of a different type.
(3) Every opening parenthesis should be eventually closed by a closing parenthesis of the same type.
Write a function named balanced that accepts the string word as an argument. Return True if the string is balanced, and False otherwise. You can assume that the string doesn't contain any characters other than parentheses.
You do not have to accept the input from the user or print output to the console. You just have to write the function definition.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | ([{}]) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | [(]) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 3 | )([] | False | False\n
| Passed after ignoring Presentation Error |
2. Programming Assignment | Week 9
Consider the problem about balanced expressions discussed in 1. Programming Assignment | Week 9. We have a balanced expression (string) that has only the flower brackets: '( )'. We can recursively define a concept called nesting depth for each pair of opening and closing brackets.
The nesting depth of a pair that lies within another pair is one more than the nesting depth of the pair that immediately englobes it. For a pair that is not surrounded by any other pair, the nesting depth is 1.
You do not have to accept the input from the user or print output to the console. You just have to write the function definition.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | (())() | 2 | 2\n
| Passed after ignoring Presentation Error |
Test Case 2 | (()(()))() | 3 | 3\n
| Passed after ignoring Presentation Error |
3. Programming Assignment | Week 9
Write a recursive function named power that accepts a square matrix A and a positive integer m as arguments and returns Am.
You do not have to accept input from the user or print the output to the console. You just have to write the function definition.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
3
1,2,3
4,5,6
7,8,9 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
2
1,2,3
4,5,6
7,8,10 | 30,36,45\n
66,81,102\n
109,134,169 | 30,36,45\n
66,81,102\n
109,134,169\n
| Passed after ignoring Presentation Error |
1. Programming Assignment | Week 10
Due on 2024-04-11, 23:59 ISTWrite a function named rotate that accepts a matrix mat as argument. It should return a matrix that is rotated by 90 degrees in the clockwise direction. For example:
You do not have to accept input from the user or print output to the console. You just have to write the function definition.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 2,3
1,2,3
4,5,6
4,1\n
5,2\n
6,3
4,1\n
5,2\n
6,3\n
Passed after ignoring Presentation Error
Test Case 2 3,2
1,2
3,4
5,6
5,3,1\n
6,4,2
5,3,1\n
6,4,2\n
Passed after ignoring Presentation Error
Test Case 3 3,3
1,2,3
4,5,6
7,8,9
7,4,1\n
8,5,2\n
9,6,3
7,4,1\n
8,5,2\n
9,6,3\n
Passed after ignoring Presentation Error
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2,3
1,2,3
4,5,6 | 4,1\n
5,2\n
6,3 | 4,1\n
5,2\n
6,3\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3,2
1,2
3,4
5,6 | 5,3,1\n
6,4,2 | 5,3,1\n
6,4,2\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3,3
1,2,3
4,5,6
7,8,9 | 7,4,1\n
8,5,2\n
9,6,3 | 7,4,1\n
8,5,2\n
9,6,3\n
| Passed after ignoring Presentation Error |
2. Programming Assignment | Week 10
Due on 2024-04-11, 23:59 ISTA n×n square matrix of positive integers is called a magic square if the following sums are equal:(1) row-sum: sum of numbers in every row; there are n such values, one for each row(2) column-sum: sum of numbers in every column; there are n such values, one for each column(3) diagonal-sum: sum of numbers in both the diagonals; there are two values
There are n+n+2=2n+2 values involved. All these values must be the same for the matrix to be a magic-square.
Write a function named is_magic that accepts a square matrix as argument and returns YES if it is a magic-square and NO if it isn't one.
Notes
(1) The cells of a magic square need not be distinct. Some or even all the cells could be identical.
(2) You do not have to accept input from the user or print output to the console. You just have to write the function definition.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 2
1 2
2 1
NO
NO\n
Passed after ignoring Presentation Error
Test Case 2 3
4 9 2
3 5 7
8 1 6
YES
YES\n
Passed after ignoring Presentation Error
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
1 2
2 1 | NO | NO\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
4 9 2
3 5 7
8 1 6 | YES | YES\n
| Passed after ignoring Presentation Error |
3. Programming Assignment | Week 10
Due on 2024-04-11, 23:59 ISTYou are given certain details of the trains that stop at a station. Your task is to store these details in a nested dictionary.
The first line of input is n, the number of trains that stop at the station. n blocks of input follow. The first line in each block corresponds to the train name. The second line in each block corresponds to m, the number of compartments in the train. m lines of input follow. Each of these m lines has two values separated by a comma: name of the compartment and number of passengers in it.
Your task is to create a nested dictionary named station_dict. The keys of the dictionary are train names, the value corresponding to a key is another dictionary. The keys of the inner dictionary are the compartment names in this train, the values are the number of passengers in each compartment. For example:
{
'Mumbai Express': {
'S1': 10,
'S2': 20,
'S3': 30
},
'Chennai Express': {
'S1': 10,
'S2': 20,
'S3': 30
}
}
(1) The values of the compartments should be represented as integers and not as strings.
(2) You do not have to print the output to the console. Do not try to print the output that you observe in the "Expected Output". You just have to process the input and create the dictionary station_dict.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 2
Mumbai Express
2
S1,10
S2,20
Chennai Express
3
S1,5
S2,10
S3,15
{'Mumbai Express': {'S1': 10, 'S2': 20}, 'Chennai Express': {'S1': 5, 'S2': 10, 'S3': 15}}
{'Mumbai Express': {'S1': 10, 'S2': 20}, 'Chennai Express': {'S1': 5, 'S2': 10, 'S3': 15}}\n
Passed after ignoring Presentation Error
Test Case 2 1
Rajdhani Express
5
S1,1
S2,2
S3,10
S4,20
S5,20
{'Rajdhani Express': {'S1': 1, 'S2': 2, 'S3': 10, 'S4': 20, 'S5': 20}}
{'Rajdhani Express': {'S1': 1, 'S2': 2, 'S3': 10, 'S4': 20, 'S5': 20}}\n
Passed after ignoring Presentation Error
You are given certain details of the trains that stop at a station. Your task is to store these details in a nested dictionary.
The first line of input is n, the number of trains that stop at the station. n blocks of input follow. The first line in each block corresponds to the train name. The second line in each block corresponds to m, the number of compartments in the train. m lines of input follow. Each of these m lines has two values separated by a comma: name of the compartment and number of passengers in it.
Your task is to create a nested dictionary named station_dict. The keys of the dictionary are train names, the value corresponding to a key is another dictionary. The keys of the inner dictionary are the compartment names in this train, the values are the number of passengers in each compartment. For example:
{
'Mumbai Express': {
'S1': 10,
'S2': 20,
'S3': 30
},
'Chennai Express': {
'S1': 10,
'S2': 20,
'S3': 30
}
}
(1) The values of the compartments should be represented as integers and not as strings.
(2) You do not have to print the output to the console. Do not try to print the output that you observe in the "Expected Output". You just have to process the input and create the dictionary station_dict.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
Mumbai Express
2
S1,10
S2,20
Chennai Express
3
S1,5
S2,10
S3,15 | {'Mumbai Express': {'S1': 10, 'S2': 20}, 'Chennai Express': {'S1': 5, 'S2': 10, 'S3': 15}} | {'Mumbai Express': {'S1': 10, 'S2': 20}, 'Chennai Express': {'S1': 5, 'S2': 10, 'S3': 15}}\n
| Passed after ignoring Presentation Error |
Test Case 2 | 1
Rajdhani Express
5
S1,1
S2,2
S3,10
S4,20
S5,20 | {'Rajdhani Express': {'S1': 1, 'S2': 2, 'S3': 10, 'S4': 20, 'S5': 20}} | {'Rajdhani Express': {'S1': 1, 'S2': 2, 'S3': 10, 'S4': 20, 'S5': 20}}\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.