Question 1
Given the created and deleted dates for a server, create a program that calculates the cost. The
fee structure is as follows:
1. If the server is deleted on the same day it is created, there is a fixed cost of 20.
2. If the server is deleted after a day but still within a month cost = 30 * (the number of
days).
3. If the server is deleted after a month but still within a year, the cost = 1000 * (the
number of months).
4. If the server is deleted after a year in which it was created, there is a fixed cost of
20000.
Function Description
Complete the server_cost function in the file. It must return an integer representing the cost.
server_cost has the following parameter(s):
d1, m1, y1: created date day, month and year
d2, m2, y2: deleted date day, month and year
Output Format
Print a single integer denoting the cost for the server as input.
Sample Input
6 6 2020
9 6 2020
Sample Output
90
Question 2
Consider a base 26 system wherein the letters of the alphabets are the digits.
That is A=0, B=1, C=2….Z=25, AA=26, AB=27,... in base 10
Write a program that will take an input string of alphabets, use the first half of the string as a
number in the base26 system and the other half as another number in the base26 system.
Now, add these two numbers to obtain a sum in base10.
Accept the string only if it contains an even number of characters otherwise, return 0.
As the second part of the program, write a function to convert the base10 number you have
obtained back to base 26.
Example, first function: - If your input string is “Petpan”, then first split it into PET 26 and PAN26.
And show the sum in base10.
Example, second function:- Pass both base10 numbers 10145(PET) and 10039(PAN). The
output should be PETPAN.
First Function
------------------
Sample Input
“Petpan”
Sample Output
20184
Second Function
-----------------------
Sample Input
10145, 10039
Sample Output
“PETPAN”
Question 3
A TV Channel has ad slots running for exactly 30 seconds or multiple of 30.
You are given a list of ads where the ith ad has running time (video length) of length[i] seconds.
Return the no. of pairs of ads for which their total running time in seconds is a multiple of 30.
Example 1:
Input:
length = [15, 10, 75, 50, 20]
Output:
Explanation:
Three pairs of ads have running time in seconds as multiple of 30
15, 75 = 90 seconds
10, 50 = 60 seconds
10, 20 = 30 seconds
Example 2:
Input:
length = [30, 30, 30]
Output:
Explanation:
All three pairs have a running time of 30 seconds