Strings
Strings
Given a string of odd length greater 7, return a string made of the middle three
chars of a given String
For example: –
getMiddleThreeChars("JhonDipPeta") → "Dip"
getMiddleThreeChars("Jasonay") → "son“
Expected Output:
Input:
PyNaTive
Output:
arranging characters giving precedence to lowercase letters:
yaivePNT
Question 3
Concatenate two lists index-wise
Input:
list1 = ["M", "na", "i", "Ke"]
list2 = ["y", "me", "s", "lly"]
Expected output:
['My', 'name', 'is', 'Kelly']
Question 4
Input - A string of numbers
Output - Check if the number is palindrome. If it is, print it's length.
If not, ( get the reverse of the string, add it to the original string, and check
again). Repeat until a palindrome is generated.
2. Input - 4,
Output - 1.
# 4 is a palindrome.
Question 5
Little Robert likes mathematics. Today his teacher has given him two integers
and asked to find out how many integers can divide both the numbers. Would
you like to help him in completing his school
assignment?
Input Formatting: There is two integers, a and b as input to the program.
Output Formatting: Print the number of common factors of a and b. Both the
input value should be in a range of 1 to 10^12.
Example:
Input: 10 15
Output: 2
Explanation: The common factors of 10 and 15 are 1 and 5. So the
answer will be 2.
Question 6
Consider a permutation of numbers from 1 to N written on a paper. Let’s denote
the product of its element as ‘prod’ and the sum of its elements as ‘sum’. Given a
positive integer N, your task is to determine whether ‘prod’ is divisible by ‘sum’ or
not.
Input Format: First input will be an integer T. It depicts a number of test cases.
Followed by value for each test cases. Each test case will contain an integer N
(1<= N <=10^9). It is nothing but the length of the permutation.
Output Format: For each test case, print “YEAH” if ‘prod’ is divisible by ‘sum’,
otherwise print “NAH”.
Question 6
Input:
2
2
3
Output:
YEAH
NAH
Explanation:
The first input is a number of test cases.
Iterate to read all the inputs and store it in the Python list.
For each element in the list, calculate prod and sum.
Print “YEAH” if the prod is divided by the sum. Otherwise, print “NAH”.
PROBLEM STATEMENT 7
Given an integer N
N<=10^50
Output the no. of pairs (x,y) such that
0<=x<=n
0<=y<=n
F(x) + F(y) = Prime number
Note : (x,y) and (y,x) are to be treated as same pair
Example
Input
3
Output
5
Explanation
5 pairs (0,2), (1,1), (0,3), (2,3), (1,2) give prime no.s
PROBLEM STATEMENT 8
Given a string, count all distinct substrings of the given string.
Example
Input
abcd
Output
10
All Elements are Distinct
Input
aaa
Output
3
PROBLEM STATEMENT 9
In Hackerland every character has a weight. The weight of an English uppercase alphabet A-
Z is given below :
A=1
B = 2*A + A
C = 3*B + B
D = 4*C + C
….
Z = 26*Y + Y
The weight made up of these characters is the summation of weights of each character.
Given a total string weight, determine shortest string of given weight. If there is more than
one solution, return the lexicographically smallest of them. For example, given weight = 25,
and the weights of the first few characters of the alphabets are A=1, B=3, C=12, D=60 it is
certain that no letter larger than C is required. Some of the strings with a total weight equal to
the target are ABBBBC, ACC, AAAAAAABBBBBB. The shortest of these is ACC. While any
permutation of these characters will have same weight, this is the lexicographically smallest
of them.
PROBLEM STATEMENT 9
Example
Input
20
Output
AABBC
PROBLEM STATEMENT 10
Consider a string, group the similar characters in combinations. Then, concatenate
first element and last element alternatively.
For instance, Consider a string “HelLoWOrld”, combinations of similar characters will
be:
[‘d’, ‘e’, ‘H’, ‘lLl’, ‘oO’, ‘r’, ‘W’]
So, final output : dWerHoOlLl
Input:
First Input : s, string
Output:
String [Manipulated]
Constraints:
1 ≤ T ≤ 70
2 < N ≤ 10000
PROBLEM STATEMENT 10
Test Cases:
Test Cases:
0
PROBLEM STATEMENT 13
Given a row/column count and a matrix, your job is to find those possible 2*2 matrix
where each should follow the given rule :
Each element of matrix should be divisible by sum of its digits.
Input Format :
First Input : Row count, Column Count
Second Input : Matrix
Output Format :
2*2 matrices satisfying the rule.
PROBLEM STATEMENT 13
Test Cases:
24 27
190 40
PROBLEM STATEMENT 14
You are given a list of numbers from 1 to 9, in which each number is separated by ‘,’.
Your job is to find the sum of two numbers. These two numbers are needed to be
calculated as per following rules :
1. First number should be calculated as :
Add all the numbers that do not come between 4 and 7 in the input.
2. Second number should be calculated as :
Append all the numbers to each other that comes between 4 and 7 (inclusive).
Find the sum of both calculated numbers.
Note : 4 always comes before 7.
Input :
First Input : List of numbers
Output :
Sum of both calculated numbers
PROBLEM STATEMENT 14
Test Cases:
1,3,4,6,8,7,2,9 4702
PROBLEM STATEMENT 15
Given a list of numbers and a special sum. Find all those combinations from the
given list and print the count of combinations whose sum is equal to the given sum.
Input :
First Input : list of numbers
Second Input : Sum value
Output :
Count of Combinations satisfying criteria
Test Cases:
Sample Input Sample Output
1,4,2,1,3,2 4
8
PROBLEM STATEMENT 16
Write a python program that it should consist of special char, numbers and chars .
1) If there are even numbers of special chars then:
the series should start with even followed by odd
Input: t9@a42&516
Output: 492561
2) If there are odd numbers of special chars then the output will be starting with odd followed by
Even:
Input: 5u6@25g7#@
Output: 56527
Input: “xxAbcxxAbcxx”
Output: 2