Posts

Plant Growth Calculation

Plant Growth Calculation In a matrix containing R rows and C columns, various plants are planted. The growth of a given plant in a calendar month depends on it's current height at the beginning of the month. If the current height is a prime number, the height by which the plant grows in that month is equal to the current height minus previous prime number (If there is no previous prime number consider the previous prime number as zero). If the current height is not a prime number then the height by which the plant grows in that month is equal to the sum of the unit digits of the adjacent plants height at the beginning of the month (If there is no adjacent plant to left or right consider the value as zero). Given the current height of the plants at the beginning of first month, print the height of the plants after N months.  Input Format:  The first line contains R and C separated by a space. Next R lines contains C values representing the height of the plants (with the values ...

Common Alphabets N Strings

Common Alphabets N Strings: Problem: N string values are passed as input to the program. Each string will contain only the alphabets a-z in lower case. A given alphabet may be repeated any number of times. The program must print the count C of the alphabets that are present in all the N string values.  Input Format:  The first line contains N. Next N lines contain the N string values.  Output Format:  The first line contains C.  Boundary Conditions:  2 <= N <= 500  1 <= Length of the string value <= 1000  Example Input/Output 1:  Input:  3  mnppqqr  ajkmnnm  poormanagement  Output:  2  Explanation:  Only 2 alphabets m and n are present in all the three string values. Program: n  =  int ( input ()) d  =  dict ()  for   i   in   range ( n ):       s  =  set ( input (). strip ())      for   j ...

Expand alphabets occurrence

Expand alphabets occurrence  Problem:  A string consisting of short hand form of occurrence of alphabets will be passed as input. The program must expand the code and print the alphabets. Input Format: The first line will contain the short hand form of the code of length L.  Boundary Conditions:  2 <= L <= 20  Output Format: The alphabets occurrence based on the short hand code.  Example Input/Output 1:  Input:  a3b5a2  Output:  aaabbbbbaa  Explanation:  a3 implies a has to occur 3 times and hence a is printed thrice. b5 implies b has to be occur five times and hence b is printed five times. a2 again implies a has to occur 2 times and hence a is printed thrice. Example Input/Output 2:  Input:  z2m6c4  Output:  zzmmmmmmcccc  Example Input/Output 3:  Input:  abc5  Output:  aaaaabbbbbccccc  Explanation:  Here there is no number after a and b. This implies the next immedi...

Letters at position of multiples of a number

Letters at position of multiples of a number   Problem: A string of length L consists of characters is passed as input to the program. A given number N is also passed as the input to the program. The program must print the characters at the positions which are multiples of the given number.  Input Format:  The first line will contain the string of length L.  The second line will contain the number N.  Boundary Conditions:  3 <= L <= 50  1 <= N <= 30  Output Format:  The characters at the positions which are multiples of the given number.  Example Input/Output 1:  Input:  abcdef  3  Output:  cf  Explanation:  Multiples of 3 are like 3,6,9,... So the characters at positions 3,6 namely c and f are printed as output.  Example Input/Output 2:  Input:  environment  2  Output:  niomn  Explanation:  As it must be multiples of 2, the characters at even pos...

Jersey Number - Highest in Team

Jersey Number - Highest in Team  Problem:  In a school there are N students standing in a straight line. Their Jersey numbers from left to right are passed as the input. The students are to be divided into teams of size T starting from left. First T students form Team 1, next T students form Team 2 and so on. If N is not divisible by T and say the remainder is R, the R students are distributed among the teams formed so far in a round robin fashion (starting from the first team) until the R students are assigned to one of the teams. Once the teams are formed, the program must print the highest jersey number in each team.  Input Format:  The first line contains N. The second line contains the jersey numbers of N students separated by a space. The third line contains T.  Output Format:  The highest jersey number in each team separated by a space.  Boundary Conditions:  1 <= N <= 9999999  Example Input/Output 1:  Input:  10  ...

Factor Count - Integer

Factor Count - Integer    A number N is passed as input. The program should print the count of factors for the number N.  Input Format:  The first line will contain the number N.  Output Format:  The first line will contain the count of factors for the number N.  Boundary Condition(s):  1 <= N < 10^7  Example Input/Output 1:  Input:  100  Output:  9  Example Input/Output 2:  Input:  6  Output:  4 Program: n = int(input()) f = 0 for i in range(1,n+1):     if n%i == 0:         f += 1  print(f)        

Check Sorted Order

Check Sorted Order   The program must accept N integers which are sorted in ascending order except one integer. But if that single integer R is reversed, the entire array will be in sorted order. The program must print the first integer that must be reversed so that the entire array will be sorted in ascending order.  Boundary Condition(s):  2 <= N <= 20  Input Format:  The first line contains N. The second line contains N integer values separated by a space.  Output Format:  The first line contains the integer value R.  Example Input/Output 1:  Input:  5  10 71 20 30 33  Output:  71  Explanation:  When 71 is reversed the array becomes sorted as below. 10 17 20 30 33  Example Input/Output 2:  Input:  6  10 20 30 33 64 58  Output:  64  Example Input/Output 3:  Input:  6  10 20 30 33 67 58  Output:  58  Program: n = int(input()) l = list(ma...