Professional Documents
Culture Documents
Positive Negative Pairs: Input Format
Positive Negative Pairs: Input Format
Given list of integers, print all the pairs having a positive value and negative value of
a number that exists in the list. We need to print pairs in order of their occurrences.
A pair whose any element appears first should be printed first.
Input Format
Constraints
N >0.
Output Format
Sample Input 0
8
4 8 9 -4 1 -1 -8 -9
Sample Output 0
4 -4 8 -8 9 -9 1 -1
CODE:
n=int(input())
li=list(map(int,input().split()))
catli=[]
for i in li:
print(i,-i,end=" ")
catli.append(i)
catli.append(-1*i)
8
4 8 9 -4 1 -1 -8 -9
4 -4 8 -8 9 -9 1 -1
Expected Output
4 -4 8 -8 9 -9 1 -1
Range count
Count the number of list elements with values given in the range.
Given an unsorted list of size n, find number of elements between the range i and j
(both inclusive).
Input Format
Constraints
Nil
Output Format
Output consists of the number of list elements lying between the closed interval of
the given range.
Sample Input 0
6
1 3 3 9 10 4
14
Sample Output 0
4
Sample Input 1
6
1 3 3 9 10 4
12 9
Sample Output 1
2
CODE:
n=int(input())
li=list(map(int,input().split()))
key=list(map(int,input().split()))
cnt=0
if key[0]>key[1]:
temp=key[0]
key[0]=key[1]
key[1]=temp
for i in li:
cnt=cnt+1
print(cnt)
Expected Output
6
1 3 3 9 10 4
12 9
Expected Output
Multiplication Challenge
Janu and Banu are playing a multiplication game, If Janu tells a set of numbers,
Banu needs to multiply first number with second number, third number with fourth
number , fifth number with six number and so on. Help Banu to do this calculation.
Also, if Janu tells odd set of numbers, Banu should tell "You are FOOL"
Input Format
Nil
Output Format
Sample Input 0
6
1 23 10 5 7 11
Sample Output 0
23 50 77
Sample Input 1
5
23 10 5 7 11
Sample Output 1
You are FOOL
6
1 23 10 5 7 11
23 50 77
Expected Output
23 50 77
5
23 10 5 7 11
Expected Output
Marks Range 1
Develop a program that will read a list of student marks in the range 0 ... 100 and
tell you how many students scored in each range of 10 - how many scored 0 - 9,
how many 10 -19, 20 - 29 ... and so on.
Input Format
Input consists of one positive integer which intimates the number of elements in
the list
Constraints
Nil
Output Format
Sample Input 0
7
23 45 76 103 87 -12 84
Sample Output 0
0-9: 0
10-19: 0
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 0
Invalid: 2
Sample Input 1
7
23 45 76 99 87 12 84
Sample Output 1
0-9: 0
10-19: 1
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 1
Invalid: 0
n=int(input())
a,b,c,d,e,f,g,h,m,j,k=0,0,0,0,0,0,0,0,0,0,0,
for i in lst:
a+=1
b+=1
c+=1
d+=1
e+=1
f+=1
h+=1
m+=1
j+=1
else:
k+=1
print('0-9: {}'.format(a))
print('10-19: {}'.format(b))
print('20-29: {}'.format(c))
print('30-39: {}'.format(d))
print('40-49: {}'.format(e))
print('50-59: {}'.format(f))
print('60-69: {}'.format(g))
print('70-79: {}'.format(h))
print('80-89: {}'.format(m))
print('90-100: {}'.format(j))
print('Invalid: {}'.format(k))
7
23 45 76 103 87 -12 84
0-9: 0
10-19: 0
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 0
Invalid: 2
Expected Output
0-9: 0
10-19: 0
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 0
Invalid: 2
7
23 45 76 99 87 12 84
0-9: 0
10-19: 1
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 1
Invalid: 0
Expected Output
0-9: 0
10-19: 1
20-29: 1
30-39: 0
40-49: 1
50-59: 0
60-69: 0
70-79: 1
80-89: 2
90-100: 1
Invalid: 0
Input Format
Constraints
Nil
Output Format
Sample Input 0
9
-2 1 -3 4 -1 2 1 -5 4
Sample Output 0
Sum : 6
4 -1 2 1
n=int(input())
b=[]
c=[]
n=len(a)
for i in b:
c.append(sum(i))
d=c.index(max(c))
print('Sum : {}'.format(c[d]))
print(*b[d])
9
-2 1 -3 4 -1 2 1 -5 4
Sum : 6
4 -1 2 1
Expected Output
Sum : 6
4 -1 2 1
Identity matrix 4
Write a program to check if a given matrix is an Identity Matrix
Input Format
Matrix elements
Constraints
Nil
Output Format
Sample Input 0
33
111
222
333
Sample Output 0
Not an identity matrix
Sample Input 1
33
100
010
001
Sample Output 1
Identity matrix
m,n=map(int,input().split(' '))
matrix=[]
ans=1
for i in range(m):
a=[]
matrix.append(a)
ans=0
break
ans=0
break
if ans:
print('Identity matrix')
else:
33
111
222
333
Expected Output
33
100
010
001
Identity matrix
Expected Output
Identity matrix
Equal matrix
Write a Program to check if two Matrices are Equal or not
Input Format
Constraints
Nil
Output Format
Sample Input 0
23
123
654
123
654
Sample Output 0
Equal
Sample Input 1
23
123
654
123
655
Sample Output 1
Not equal
m,n=map(int,input().split(' '))
matrix=[]
matrix2=[]
ans=0
for i in range(m):
a=[]
matrix.append(a)
for i in range(m):
a=[]
matrix2.append(a)
for i in range(m):
for j in range(n):
if matrix[i][j]==matrix2[i][j]:
ans=1
else:
ans=0
break
if ans==1:
print('Equal')
else:
print('Not equal')
Congratulations, you passed the sample test case.
Click the Submit Code button to run your code against all the test cases.
Input (stdin)
23
123
654
123
654
Equal
Expected Output
Equal
23
123
654
123
655
Not equal
Expected Output
Not equal
Example
Input: 3 3
101
000
100
Output: Yes
Input Format
Binary matrix
Constraints
Binary matrix
Output Format
Yes or No
Sample Input 0
33
101
000
100
Sample Output 0
Yes
Sample Input 1
33
101
101
111
Sample Output 1
No
matrix = []
check=0
for i in range(m):
res=0
a = []
res=int("".join(map(str,a)))
matrix.append(res)
ans=[]
for i in matrix:
if i not in ans:
ans.append(i)
else:
check=1
if check:
print('No')
else:
print('Yes')
33
101
000
100
Yes
Expected Output
Yes
33
101
101
111
No
Expected Output
No
Normal: Square root of the sum of the squares of each element of the matrix.
Constraints
Nil
Output Format
Output prints the trace and normal separated by a space. Refer sample output.
Sample Input 0
33
123
456
789
Sample Output 0
15 16.88
Sample Input 1
45
Sample Output 1
Invalid Input
m,n=map(int,input().split(' '))
matrix=[]
if m!=n:
print('Invalid Input')
else:
for i in range(m):
a=[]
matrix.append(a)
res=0
ans=0
for i in range(m):
for j in range(n):
if i==j:
res+=matrix[i][j]
for i in range(m):
for j in range(n):
temp=matrix[i][j]
ans=ans+(temp*temp)
ans=ans**0.5
print(res,end=' ')
print('%.2f'%ans)
33
123
456
789
15 16.88
Expected Output
15 16.88
45
Invalid Input
Expected Output
Invalid Input
Transpose matrix 7
Write a program to find the transpose of a given matrix.
Input Format
Matrix elements
Constraints
Nil
Output Format
Sample Input 0
33
123
456
789
Sample Output 0
147
258
369
m,n=map(int,input().split(' '))
matrix=[]
for i in range(m):
a=[]
matrix.append(a)
for i in range(n):
for j in range(m):
print(matrix[j][i],end=' ')
print()
Congratulations, you passed the sample test case.
Click the Submit Code button to run your code against all the test cases.
Input (stdin)
33
123
456
789
147
258
369
Expected Output
147
258
369