Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

PBT|DAILY TEST|9 JUN CODING ONLY

 CONTAINS ONLY CODING SECTION

 

 

PROGRAMMING :

Problem Statement
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky
that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates (x,y), such that x1≤x≤x2 and y1≤y≤y2,
where (x1,y1) and (x2,y2) are coordinates of the left bottom and the right top corners of the rectangle
being photographed. The area of this rectangle can be zero.
After taking the photo, Pavel wrote down coordinates of n of his favourite stars which appeared in the
photo. These points are not necessarily distinct, there can be multiple stars in the same point of the
sky.
Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the
dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not
much help; numbers are written in random order all over his notepad, so it's impossible to tell which
numbers specify coordinates of which points.
Pavel asked you to help him to determine what are the possible dimensions of the photo according to
his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of
the rectangle.
Input Format
The first line of the input contains an only integer n , the number of points in Pavel's records.
The second line contains 2⋅n integers a1, a2, ..., a2⋅n , coordinates, written by Pavel in some order.
Constraints
(1≤n≤100000) (1≤ai≤10^9)
Output Format
Print the only integer, the minimal area of the rectangle which could have contained all points from
Pavel's records.


PYTHON CODE:

n=int(input())
a=sorted(map(int,input().split()))
print(min([(a[n-1]-a[0])*(a[-1]-a[n])]+[(a[-1]-a[0])*(y-x)
for x,y in zip(a,a[n-1:])]))

 

 

2.

Problem Statement
There was an electronic store heist last night.
All keyboards which were in the store yesterday were numbered in ascending order from some integer
number x. For example, if x=4 and there were 3 keyboards in the store, then the devices had indices 4,
5 and 6, and if x=10 and there were 7 of them then the keyboards had indices 10, 11, 12, 13, 14, 15 and 16.
After the heist, only n keyboards remain, and they have indices a1,a2,…,an. Calculate the minimum
possible number of keyboards that have been stolen. The staff remember neither x nor the number of
keyboards in the store before the heist.
Input Format
The first line contains single integer n — the number of keyboards in the store that remained after the
heist.
The second line contains n distinct integers a1,a2,…,an — the indices of the remaining keyboards. The
integers ai are given in arbitrary order and are pairwise distinct.
Constraints
(1≤n≤1000)
(1≤ai≤10^9)
Output Format
Print the minimum possible number of keyboards that have been stolen if the staff remember neither x
nor the number of keyboards in the store before the heist.

 

PYTHON CODE:

n=int(input())
a=[*map(int,input().split())]
print(max(a)-min(a)-n+1)


3.

Problem Statement
Two players play a game.
Initially there are n integers a1,a2,…,an written on the board. Each turn a player selects one number and
erases it from the board. This continues until there is only one number left on the board, i. e. n−1 turns
are made. The first player makes the first move, then players alternate turns.
The first player wants to minimize the last number that would be left on the board, while the second
player wants to maximize it.
You want to know what number will be left on the board after n−1 turns if both players make optimal
moves.
Input Format
The first line contains one integer n — the number of numbers on the board.
The second line contains n integers a1,a2,…,an .
Constraints
(1≤n≤1000) (1≤ai≤10^6)
Output Format
Print one number that will be left on the board

 

python code:

 
n=int(input())
print(sorted(map(int,input().split()))[(n-1)//2])

 

********************************************************************

 



 


Post a Comment

Previous Post Next Post