Posts

Matrix - Identical Row and Column

Image
Matrix - Identical Row and Column  PROBLEM STATEMENT : The program must accept an integer matrix of size N*N as the input. The program must print YES if at least one row is identical to one column in the given matrix. Else the program must print NO as the output.  Boundary Condition(s):   2 <= N <= 50  1 <= Matrix element value <= 1000  Input Format:   The first line contains N.  The next N lines, each contain N integers separated by a space.  Output Format:  The first line contains YES or NO.  Explanation:  Example Input/Output 3: Input:  Output: NO Example Input/Output 1: Input: ( ) 4 2 3 4 5 3 5 10 9 6 10 8 8 7 9 2 1 Output: YES Explanation:  2nd row and 2nd column of the given matrix are identical.  2 3 4 5  3 5 10 9  6 10 8 8  7 9 2 1  So YES is printed as the output. Example Input/Output 2: Input: ( ) 3 4 5 3 1 3 3 4 5 1 Output: YES Explanation: ...

Corona Spread Days

Image
Corona Spread Days  PROBLEM STATEMENT : There are N chairs in a line. The program must accept N integer values denoting the seating details in these N chairs.  - 1 represents a healthy person sitting in a chair.  - 0 represents the chair is empty.  - 2 represents the chair being occupied by a Coronavirus-infected person.  Each Corona virus-infected person will affect the healthy persons sitting adjacent to him/her so that the next day those affected will, in turn, start infecting their healthy adjacent persons. The program must print the number of days D required for the virus to stop spreading and the number of persons H who remain not infected by the virus in the end.  Boundary Condition(s):   2 <= N <= 20  Input Format:  The first line contains N.  The second line contains the N integer values separated by a space.  Output Format:  The first line contains D and H separated by a space.  Example Input/Outp...

Largest Submatrix - 1s Diagonal

Image
 Largest Submatrix - 1s Diagonal  PROBLEM STATEMENT : The program must accept an integer matrix of size R*C containing only 0s and 1s as the input. The program must print the largest square submatrix where all the elements in the top-left to bottom-right diagonal are equal to 1. If two or more such largest square matrices occur, then the program must print the first occurring largest square submatrix as the output. If there is no such square submatrix, then the program must print -1 as the output.  Boundary Condition(s):  2 <= R, C <= 50  Input Format:  The first line contains R and C separated by a space.  The next R lines, each contains C integers separated by a space.  Output Format:  The lines containing the largest square submatrix where all the elements in the top-left to bottom-right diagonal are equal to 1  Example Input/Output 1: Input: ( ) 10 10 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 ...

Adjust Time - Hours, Minutes, Seconds

Image
 Adjust Time - Hours, Minutes, Seconds  PROBLEM STATEMENT : The program must accept a time T in 24-hr format (HH:MM: SS) and three integers X, Y, Z as the input. The integer X represents the number of hours to be added to the time T. The integer Y represents the number of minutes to be added to the time T. The integer Z represents the number of seconds to be added to the time T. After each adjustment of the time (add X hours, add Y minutes, and add Z seconds), the program must print the revised time as the output.  Boundary Condition(s):  1 <= X, Y, Z <= 10^6  Input Format:  The first line contains the time T in 24-hr format (HH:MM: SS).  The second line contains X, Y, and Z separated by a space.  Output Format:  The first three lines, each contains the revised time after each adjustment of the given time.  Example Input/Output 1: Input: ( ) 10:05:45 4 65 100 Output: 14:05:45 15:10:45 15:12:25 Explanation:  Here ...

Colorful Flowers Count

Image
 Colorful Flowers Count  PROBLEM STATEMENT : In a garden, there are N flower plants in a row. There are three types of plants which are given below.  Type 1: It gives only a red flower every day.  Type 2: It gives only a green flower every 2 days.  Type 3: It gives only a blue flower every 3 days.  Initially, there are no flowers in the N plants. The program must accept N characters denoting the colors of the N plants and N integers denoting the maximum number of flowers that the plants can give. The program must print the total number of flowers in each color that the gardener can get in T days. The value of T is also passed as the input.  Boundary Condition(s):  1 <= N <= 100  1 <= Each integer value <= 1000  2 <= T <= 1000  Input Format:  The first line contains N.  The second line contains N characters separated by a space.  The third line contains N integer values separated by a space....

Largest Square Matrix - Words

Image
 Largest Square Matrix - Words  PROBLEM STATEMENT : The program must accept a string S containing multiple words as the input. The program must form the largest possible square matrix of size N*N based on the following conditions.  - The words of equal length must be used to form the square matrix (i.e., each row in the matrix contains all the characters of a word).  - The words in the given string must be used in the order of their occurrence.  Finally, the program must print the largest possible square matrix as the output. If there are two or more such largest square matrices, the program must print the matrix with the first N words of length N as the output. If it is not possible to form such a matrix, the program must print -1 as the output.  Boundary Condition(s):   1 <= Length of S <= 1000  Input Format:  The first line contains S.  Output Format:  The lines contain the largest possible square matrix or the first line c...

Largest Odd Number

Image
 Largest Odd Number  PROBLEM STATEMENT : The program must accept a string S and print the largest odd number L present in S. If there is no odd number in S, the program must print 0 as the output.  Boundary Condition(s):  1 <= Length of S <= 100  Input Format:  The first line contains S.  Output Format:  The first line contains L or 0 as per the given condition.  Example Input/Output 1: Input: ( ) 123456 Output: 12345 Explanation:  Here S = 123456 , the odd integers present in the string 123456 are given below  1  123  12345  23  3  2345  345  45  5  The largest odd integer in the string is 12345 . So 12345 is printed as the output.  Example Input/Output 2: Input: ( ) 4466 Output: 0                                          1)     L EARN ...