PBT DAILY TEST JUNE 12
**** CONTAINS CODING PART ONLY ****
1.
Problem Statement
You are given with an array of numbers, Your task is to print the difference of indices of largest and
smallest number. All number are unique.
Input Format
First line contains a number ‘n’. Then next line contains n space separated numbers.
Constraints
1<=n<=100 1<=elements in array<=1000
Output Format
Print the difference of indices of largest and smallest array
PYTHON CODE :
a=int(input())
b=list(map(int,input().split()))
print(b.index(max(b))-b.index(min(b)))
********************************************************************************
2.
Problem Statement
You are given with two arrays. Your task is to merge the array such that first array is in ascending
order and second one in descending order.
Input Format
First line contains two integer ‘n’ and ‘m’. ‘n’ denotes length of array 1 and ‘m’ of array 2.
Next line contains n space separated numbers and third line contains ‘m’ space separated numbers
Constraints
1>=n<=100
Output Format
Print a single array in desired order
PYTHON CODE :
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort(reverse=True)
for i in b:
a.append(i)
print(*a)
******************************************************************************
3.
Problem Statement
You are given an array of numbers. Print the least occurring element. If there is more than 1 element
print all of them in decreasing order of their value.
Input Format
You are given a number ‘n’ denoting size of array. Next line contains n space separated numbers.
Constraints
1<=n<=100
Output Format
Print the number as mentioned
PYTHON CODE :
from collections import Counter
n=int(input())
m=list(map(int,input().split()))
x=[]
a=""
d1=dict(Counter(m))
k=min(d1,key=d1.get)
l=d1[k]
for i,j in d1.items():
if j==l:
x.append(i)
x=sorted(x)
x.reverse()
print(*x,sep=" ")
Post a Comment