Thursday, August 31, 2017

Complete Cell State After D Days

There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells (neighbours). Each day, for each cell, if it's neighbours are both active or both inactive, the cell becomes inactive the next day, otherwise it becomes active the next day. The two cells at the ends have only single adjacent cell, so the other imaginary adjacent cell can be assumed...
Share:

Wednesday, August 30, 2017

Square Matrix - Corner Elements Sum

A square matrix of size N×N is passed as the input. The program must calculate and print the sum of the elements in the corners. Input Format: The first line will contain the value of N. The next N lines will contain the N values separated by one or more spaces. Output Format: The first line will contain the integer value denoting the sum of the elements in the corners. Boundary Conditions:...
Share:

Tuesday, August 29, 2017

Rotate String - N Positions

A string S of length L is passed as the input. The program must rotate the string S by N position in forward direction and print the result as the output. Input Format: The first line will contain the value of S. The second line will contain N. Output Format: The first line will contain the rotated string value. Boundary Conditions: The length L of the string S is from 3 to 100. 0 <=...
Share:

Range Start and End Position

N integers are passed as input. X which is an integer is also passed as the input. The program must print the start S and end E positions of X in these N integers. -1 must be printed as the start and end positions when X is not present in these N numbers. Input Format: The first line contains N. The second line contains N integer values separated by a space. The third line contains X. Output Format:...
Share:

Count the primes in a range

Two whole numbers N1 and N2 are passed as input. The program must print the number of primes present between N1 and N2 (the range is inclusive of N1 and N2) Input Format: First line will contain the value of the first number N1 Second line will contain the value of the second number N2 Output Format: First line will contain the count of prime numbers between N1 and N2 Sample Input/Output:...
Share:

Saturday, August 26, 2017

Peak Elements Count

N integers are passed as input. The program must print the count of peak elements among the N integers. An element is a peak element if it is greater than it's neighbours (the elements to the left and right). The elements present in the extreme left and right can never be peak elements. Input Format: The first line contains N. The second line contains N integer values separated by a space....
Share:

Monday, August 21, 2017

Shirt - Matching Pairs

A shop to increase sales during a festival has an offer that a customer will get a discount if the customer buys shirts having same size in pairs. Any customer who buys will choose N shirts and the size of the shirt is denoted by S(i) where 1 <= i <=N. Two shirts S(i) and S(j) are matching and form a pair only if S(i) = S(j). The program must print the number of pairs eligible for the discount....
Share:

Sunday, August 20, 2017

Rounding Marks

In a college, each student receives marks M in any of the subjects in the range from 0 to 100. - If the difference between the marks and the next multiple of 5 is less than 3, then round the marks up to the next multiple of 5. - If the difference between the marks and the next multiple of 5 is more than or equal to 3, then leave the marks as it is. - If the marks obtained is less than or equal to...
Share:

Tuesday, August 15, 2017

Turning Book Pages

A book can be turned either from front or from the back. When we open a book always we have the page 1 always on the right. The book pages must always be turned one by one instead of multiple pages at once. Each page has two sides, front and back. Hence the last page may have only front side depending on the total number of pages N in the book (If N is even, it will have both sides printed else...
Share:

Monday, August 14, 2017

Farmer - Breaking Yield Records

A farmer wishes to track during each harvest if he has broken previous best or worst records. The yield (in certain units) is passed as input to the program and the program must print how many times he broke his best record along with the number of times he broke his worst record. Input Format: The first line will contain the value of N which represents the units harvested in a specific yield. The...
Share:

Sunday, August 13, 2017

Exact Capacity Booking

Fed up of overbooking in airlines industry, the government has ordered that airlines cannot book more than the capacity C of an aeroplane. To optimize their revenue, the airlines must confirm booking exactly for C passengers only. The ticket may be booked for just a single passenger or for a group of passengers ranging from 2 to N. (Like 2 tickers for a couple going on a honey moon or 4 tickets...
Share:

Pet Store Dogs

There is a per store in a city where dogs can be kept when their owners go for a long tour out of the city or the owners travel abroad. The cage in the pet store can accommodate two dogs. But certain dogs are very aggressive and must be kept along in a cage and hence cannot be put in the cage along with another dog. Given the number of dogs N and assuming that a given dog can be either aggressive...
Share:

Thursday, August 10, 2017

Peanut Packing

A man is running a super market and he observes the pattern of customer buying peanuts in packs of 1 kg, 2 kgs, 3 kgs till N kgs. So based on the buying pattern and his observation he can price the packs of 1 kg, 2 kgs, ... N kgs at rupees P(1), P(2), P(3), ... P(N) respectively. What is the maximum revenue he can earn when selling N kgs of peanuts based on the given pricing? Input Format: The...
Share:

Tuesday, August 8, 2017

Triangle Pattern - Modified Pascal

Given an integer N, print a triangle as mentioned in the below examples. Input Format: The first line contains N. Output Format: N lines containing the triangle pattern as shown in the example input/output. Boundary Conditions: 1 <= N <= 999 Example Input/Output 1: Input: 4 Output:       1                                                                                                                                                                 ...
Share: