0% found this document useful (0 votes)
8 views

questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

questions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Check if two arrays are equal or not

1.)
Check if two arrays are equal or not

Given two arrays, arr1 and arr2 of equal length N, the task is to determine if the given arrays are
equal or not. Two arrays are considered equal if:

Both arrays contain the same set of elements.


The arrangements (or permutations) of elements may be different.
If there are repeated elements, the counts of each element must be the same in both arrays.

Input: arr1[] = {1, 2, 5, 4, 0}, arr2[] = {2, 4, 5, 0, 1}


Output: Yes

Input: arr1[] = {1, 2, 5, 4, 0, 2, 1}, arr2[] = {2, 4, 5, 0, 1, 1, 2}


Output: Yes

Input: arr1[] = {1, 7, 1}, arr2[] = {7, 7, 1}


Output: No

2.)

There are N different types of colours numbered from 1 to N. Chef has Ai balls having
colour i, (1≤i≤N).

Chef will arrange some boxes and put each ball in exactly one of those boxes.
Find the minimum number of boxes Chef needs so that no box contains two balls of same colour.

Input Format
 The first line of input will contain a single integer T, denoting the number of test cases. The
description of the test cases follows.
 The first line of each test case contains a single integer N, denoting the number of colors.
 The second line of each test case contains N space-separated integers A1,A2,…,AN —
denoting the number of balls having colour i.

Output Format
For each test case, output the minimum number of boxes required so that no box contains two balls
of same colour.

Input Output
3 8
2 15
85 4
3
5 10 15
4
4444

Read T

for i in range T
Read n

array = list(map(int,input().split()))

max = -1

for j in range n
if array[i] > max

max = array[i]

print max

3)

Chef is fan of pairs and he likes all things that come in pairs. He even has a doll collection in which
the dolls come in pairs. One day while going through his collection he found that there are odd
number of dolls. Someone had stolen a doll!!!
Help chef find which type of doll is missing..

Input
The first line contains an integer T, the number of test cases.
The first line of each test case contains an integer N, the number of dolls.
The next N lines are the types of dolls that are left.

Output
For each test case, display the type of doll that doesn't have a pair, in a new line.

Input Output
1 2
3
1
2
1
4.)

There are 2 stores in Chefland and both sell the same product. The first store sells the
product for 100 rupees whereas the second store sells it for 200 rupees.

It is the holiday season and both stores have announced a special discount. The first store
is providing a discount of A percent on its product and the second store is providing a
discount of B percent on its product.

Chef is wondering which store is selling the product at a cheaper price after the discount
has been applied. Can you help him identify the better deal?

Input Format
•The first line of input will contain a single integer T, denoting the number of test cases.
•Each test case consists of a single line of input containing two space-separated
integers A and B denoting the discount provided by the first and second store
respectively.

Output Format
For each test case, output FIRST if the first store is cheaper, SECOND if the second store is
cheaper, and BOTH if both the stores are selling the product for the same price after
discount.
The checker is case-insensitive so answers like FiRsT, first, and FIRST would be considered
the same.

Input
4
5 20
10 60
77
10 55
Output
FIRST
SECOND
FIRST
BOTH

A= 100-(100*X/100)
B = 200-(200*Y/100)

5.)

Raj is watching a football match. The current score is A:B, that is, team 1 has
scored A goals and team 2 has scored B goals. Raj wonders if it is possible for the score to
become C:D at a later point in the game (i.e. team 1 has scored C goals and team 2 has
scored D goals). Can you help Raj by answering his question?

Input Format
•The first line contains a single integer T - the number of test cases. Then the test cases
follow.
•The first line of each test case contains two integers A and B - the intial number of goals
team 1 and team 2 have scored respectively.•The second line of each test case contains two integers
C and D - the final number of
goals team 1 and team 2 must be able to score respectively.

Output Format
For each testcase, output POSSIBLE if it is possible for the score to become C:D at a later
point in the game, IMPOSSIBLE otherwise.
You may print each character of POSSIBLE and IMPOSSIBLE in uppercase or lowercase (for
example, possible, pOSsiBLe, Possible will be considered identical).

Input
3
1 5
3 5
3 4
2 6
2 2
2 2

POSSIBLE
IMPOSSIBLE
POSSIBLE

Read T

for i in range T

Read A, B
Read C, D

if(c >= a and d >= b)


print possible
else
print impossible

6.)
At GIFT, denominations less than rupees 10 have stopped and now rupees 10 is the smallest
denomination.
Suppose Raj goes to buy some item with cost not a multiple of 10, then, he will be charged the cost
that is the nearest
multiple of 10.
If the cost is equally distant from two nearest multiples of 10, then the cost is rounded up.
For example, 35,38,40,44 are all rounded to 40.
Raj purchased an item having cost X (X≤100) and gave a bill of rupees 100. How much amount
will he get back?

Input Format

The first line of input will contain a single integer T, denoting the number of test cases.
Each test case consists of a single integer X, the cost of the item.

Output Format
For each test case, output the amount returned to Raj.
Input

4
35
54
80
12

Output
60
50
20
90

Read T

for i in range T
Read X

A = X% 10
if ( A !=0 and A >=5)
print 100-(X + A)
else
print 100- (X-A)

7)

Print K largest(or smallest) elements in an array


Given an array arr[] of size N, the task is to printing K largest elements in an array.
Input: [1, 23, 12, 9, 30, 2, 50], K = 3
Output: 50, 30, 23

Input: [11, 5, 12, 9, 44, 17, 2], K = 2


Output: 44, 17

8.)

Check if two arrays are equal or not

Given two arrays, arr1 and arr2 of equal length N, the task is to determine if the given arrays are
equal or not. Two arrays are considered equal if:

Both arrays contain the same set of elements.


The arrangements (or permutations) of elements may be different.
If there are repeated elements, the counts of each element must be the same in both arrays.

Input: arr1[] = {1, 2, 5, 4, 0}, arr2[] = {2, 4, 5, 0, 1}


Output: Yes

Input: arr1[] = {1, 2, 5, 4, 0, 2, 1}, arr2[] = {2, 4, 5, 0, 1, 1, 2}


Output: Yes

Input: arr1[] = {1, 7, 1}, arr2[] = {7, 7, 1}


Output: No

You might also like