Saturday, June 10, 2017

Count of common factors

Given a set of numbers, the program must find the count of the common factors C excluding 1.  Input Format:  First line will contain the integer value N representing how many numbers are passed as input. Next N lines will have the numbers.  Output Format:  First line will contain the count of common factors C. Sample Input/Output:  Example 1:  Input:  2  100  75  Output:  2  Explanation:...
Share:

Friday, June 9, 2017

Ways to repay loan

A poor man borrows a sum of N rupees from his neighbour. The neighbour is kind enough not to impose any interest on the loan. The poor man agrees to re-pay the loan by paying back either 1 rupee or 2 rupees to his neighbour. In how many distinct ways can he repay the loan?  Input Format:  The first line will contain the value of N which is the loan amount.  Output Format:  The...
Share:

Thursday, June 8, 2017

Number Odd and Even digit sum

A number N is passed as input to the program. If N has odd number of digits, the program must print "NotAccepted" and exit. If N has even number of digits, the program must print the sum of digits in odd position and also must print the sum of digits in the even position. Input Format: The first line contains the value of N Output Format: The first line contains the sum of digits in the odd...
Share:

String - Characters count

A string S containing N unique characters is passed as input to the program. The program must print the character and it's occurrence count in N lines of output. The characters with their count in the output are in the same order of occurrence as in the string S. Note: All the characters will be alphabets and in lower case.  Input Format:  The first line contains the value of S  Output...
Share:

Anagrams

Write a program to find whether the 2 given strings are anagrams or not. Anagrams are words or phrases made by mixing up the letters of other words or phrases,  Input and Output Format:  Input consists of 2 string. Assume that all characters in the string are lowercase letters or spaces and the maximum length of the string is 100. Refer sample input and output for formatting...
Share:

Strong password check

Recently a security committee decided to enforce the following rules when an employee creates/changes his/her password.  - The password must contain atleast one special character among # ! _ $ @  - The password must contain atleast two numbers - The password must contain atleast one upper case alphabet and one lower case alphabet.  - The password must have a minimum length of...
Share:

Tuesday, June 6, 2017

Kaprekar number

A Kaprekar number is a number whose square when divided into two parts and such that sum of parts is equal to the original number and none of the parts has value 0.  Given a number, the task is to check if it is Kaprekar number or not. Input : n = 13 Output : No Explanation : 13^2 = 169. Neither 16 + 9 nor 1 + 69 is equal to 13 Input  : n = 297  Output : Yes Explanation:  297^2 =...
Share:

Rotate Matrix 90 Degree Anti-Clockwise

A MxN matrix is passed as the input. The program must rotate the matrix by 90 degrees in anti-clock wise direction and print the rotated matrix as the output. Input Format:  First line will contain the value of M. Second line will contain the value of N. Next M lines will contain the N values with each value separated by one or more space.  Output Format:  N lines will contain the...
Share:

Monday, June 5, 2017

Chars To Remove For Same String Value

N string values S1, S2, S3, SN are passed as input to the program. Values of S1, S2, S3, SN are such that if one character is removed from each of these string values, then the resulting string values are equal (same). The characters to be removed from the string values named C1, C2, C3, CN will be different for each string. Input Format:  The first line will contain the value of N. The next...
Share:

Sunday, June 4, 2017

Reverse Pattern Printing - Numbers

Numbers Based on the input value of N, the program must print the pattern described below. Input Format:  First line will contain the value of N. Output Format:  N lines will contain the number pattern as described below with each value separated by a single space. Boundary Conditions:  1 <= N <= 50  Example Input/Output :  Input: 5 Output: 15 10 6 3 1 14 9 5...
Share:

Saturday, June 3, 2017

Flipping the Matrix

Sean invented a game involving a  matrix where each cell of the matrix contains an integer. He can reverse any of its rows or columns any number of times, and the goal of the game is to maximize the sum of the elements in the  submatrix located in the upper-left corner of the  matrix (i.e., its upper-left quadrant). Given the initial configurations for  matrices,...
Share: