New Year Countdown
Given date-time D, write a program to print the time left for the next New Year.Input
The input will be a single line containing the date-time in the string format similar to "Dec 30 2020 02:43 PM".Output
The output should be a single line containing hours and minutes left for the next new year in the format similar to "33 hours 17 minutes".Explanation
For example, if the given date-time is "Dec 30 2020 02:43 PM", the difference between "Dec 30 2020 02:43 PM" and "Jan 1 2021 00:00 AM" is 1 day 9 hours 17 minutes. The difference in hours and minutes is 1 * 24 + 9 hours and 17 minutes. So the output should be "33 hours 17 minutes".
Sample Input 1
Dec 30 2020 02:43 PM
Sample Output 1
33 hours 17 minutes
Sample Input 2
Jan 31 2020 04:43 AM
Sample Output 2
8059 hours 17 minutes
Weekends
Given two dates D1 and D2, write a program to count the number of Saturdays and Sundays from D1 to D2 (including D1 and D2).
The date in string format is like "8 Feb 2021".Input
The first line of input will contain date D1 in the string format.
The second line of input will contain date D2 in the string format.
Output
The output should be a single line containing two integers separated by space
Explanation
For example, if the given dates are "25 Jan 2021" and "14 Feb 2021", the Saturdays and Sundays dates from "25 Jan 2021" to "14 Feb 2021" are
"30 Jan 2021" is a Saturday
"31 Jan 2021" is a Sunday
"6 Feb 2021" is a Saturday
"7 Feb 2021" is a Sunday
"13 Feb 2021" is a Saturday
"14 Feb 2021" is a Sunday
output
Saturday: 3
Sunday: 3
Sample Input 1
25 Jan 2021
14 Feb 2021
Sample Output 1
Saturday: 3
Sunday: 3
Sample Input 2
25 May 2019
22 Dec 2021
Sample Output 2
Saturday: 135
Sunday: 135
Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B
The first line contains a single integer M.
Next M lines contain two integers Pi, Ci separated with space, where Pi denotes power and Ci denotes co-efficient of Pi for polynomial A.
After that next line contains a single integer N.
Next N lines contain two integers Pj, Cj separated with space, where Pj denotes power and Cj denotes co-efficient of Pj for polynomial B.Output
Print the addition of polynomials A and B.
If the degree of polynomial is zero and the constant term is also zero, then just print 0 to represent the polynomial.
For term Cix^Pi, if the coefficient of the term Ci is 1, simply print x^Pi instead of 1x^Pi.Explanation
Then polynomial A represents "6x^3 + 10x^2 + 5", the polynomial B represents "4x^2 + 2x + 1" and the addition of A and B is "6x^3 + 14x^2 + 2x + 6"
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
Secret Message - 2
Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.
Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.
a b c d e f g h i j k l m n o p q r s t u v w x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Input
Explanation
For example, if the given input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So the output should be "16-25-20-8-15-14".
Sample Input 1
python
Sample Output 1
16-25-20-8-15-14
Sample Input 2
Foundations
Sample Output 2
6-15-21-14-4-1-20-9-15-14-19
Secret Message - 1
Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.
Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ... , 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.
a b c d e f g h i j k l m n o p q r s t u v w x y z
z y x w v u t s r q p o n m l k j i h g f e d c b a
Explanation
Input
For example, if the given input is "python", "p" should replaced with "k", similarly "y" with "b", "t" with "g", "h" with "s", "o" with "l", "n" with "m". So the output should be "kbgslm".
Sample Input 1
python
Sample Output 1
kbgslm
Sample Input 2
Foundations
Sample Output 2
ulfmwzgrlmh
Create a second function which will take one string argument. The purpose of the function is to search the text file created in step one, and determine how many occurrences of the argument passed into the function occur in the file. Return the number of occurrences to the caller along with the word “high”, “medium” , “low” or “none” based upon the number of hits received- 0 = none, 1-5 low, 6-10 medium, 11+ high.
Write a script which will call the appropriate methods to find how many occurrences of a random word occurs in the text file. Print out the number of occurrences and keyword (with an appropriate message) along with the length of time it took to complete the search – with an appropriate message.
Elements of Anti Diagonal
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]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]
[-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
7First and Last Digits
Given two integers M and N, write a program to count of the numbers which have the same first and last digits in the given range M to N (inclusive of M and N).
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 an integer denoting the count of the numbers in the range which meet the given condition.
Explanation
For example, if the given numbers are M is 5 and N is 30, the numbers which have the first and last digit equal in the given range (5, 6, ..., 29, 30) are 5, 6, 7, 8, 9, 11 and 22. So the output should be 7.
Sample Input 1
5
30
Sample Output 1
7
Sample Input 2
1
10
Sample Output 2
9First and Last Digits
Given two integers M and N, write a program to count of the numbers which have the same first and last digits in the given range M to N (inclusive of M and N).
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 an integer denoting the count of the numbers in the range which meet the given condition.
Explanation
For example, if the given numbers are M is 5 and N is 30, the numbers which have the first and last digit equal in the given range (5, 6, ..., 29, 30) are 5, 6, 7, 8, 9, 11 and 22. So the output should be 7.
Sample Input 1
5
30
Sample Output 1
7
Sample Input 2
1
10
Sample Output 2
9