Posts

Showing posts from May, 2021

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 ...