SBT RETEST 13 JUNE 2021
TECHNICAL MCQ
1. 106 104 102 100
2. 90.50 92.50 96.50
3. 10 20 30
4. 1 11
5. 35
6. Run time error
7. 1 6
8. 3,2,32
9. 3,2,23
10. 10 10
***********************************************************
Programming :
1.
Problem Statement
Given an array of N integers, and an integer K, find the number of pairs of elements in the array whose
sum is equal to K.
Input Format
First line of input contains two space separate integers 'n' and 'k'.
Next line of input contains n integers - the elements of the array.
Constraints
1 <= N <= 105 1 <= K <= 108 1 <= Arri <= 106
Output Format
Print the number of pairs that have sum K.
C++ :
#include <bits/stdc++.h>
using namespace std;
int pairs_count(int arr[], int n, int sum)
{
int ans = 0;
sort(arr, arr + n);
int i = 0, j = n - 1;
while (i < j) {
if (arr[i] + arr[j] < sum)
i++;
else if (arr[i] + arr[j] > sum)
j--;
else {
int x = arr[i], xx = i;
while (i < j and arr[i] == x)
i++;
int y = arr[j], yy = j;
while (j >= i and arr[j] == y)
j--;
if (x == y) {
int temp = i - xx + yy - j - 1;
ans += (temp * (temp + 1)) / 2;
}
else
ans += (i - xx) * (yy - j);
}
}
return ans;
}
int main()
{int n,k;cin>>n>>k;int arr[n];
for(int i=0;i<n;i++)
{ cin>>arr[i];
}
cout << pairs_count(arr, n, k);
return 0;
}
******************************************************
2.
Problem Statement
Given an array of items, the i'th index element denotes the item id’s and given a number m, the task
is to remove m elements such that there should be minimum distinct id’s left. Print the number of
distinct id’s.
Input Format
First line of input contains 'n' the size of array. Next line contains n integers which are the elements
of the array. Next line contains an integer 'm'
Constraints
1<=n<=10000 -10000<=elements of array<=100000 1<=m<=1000
Output Format
Print the number of distinct id’s left
C++ CODE:
#include <bits/stdc++.h>
using namespace std;
int distinctNumbers(int arr[], int m,
int n)
{
unordered_map<int, int> count;
for (int i = 0; i < n; i++)
count[arr[i]]++;
vector<int> fre_arr(n + 1, 0);
for (auto it : count) {
fre_arr[it.second]++;
}
int ans = count.size();
for (int i = 1; i <= n; i++) {
int temp = fre_arr[i];
if (temp == 0)
continue;
int t = min(temp, m / i);
ans -= t;
m -= i * t;
}
return ans;
}
int main()
{int n,m;cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{cin>>arr[i];
}
cin>>m;
cout << distinctNumbers(arr, m, n);
return 0;
}
*******************************************************
3.
A peak element in an array is the one that is not smaller than its neighbours. Given an array of size
N, find the index of first peak element encountered in the array.
For corner elements, we need to consider only one neighbor.
Input Format
First line contains 'n' - the size of the array. Next line contains n integers- the n elements of array.
Constraints
2<=n<=10000 1<=elements of array<=10000
Output Format
Print index of the first peak element encountered in the array
C++ CODE:
#include <bits/stdc++.h>
using namespace std;
int findPeak(int arr[], int n)
{
if (n == 1)
return 0;
if (arr[0] >= arr[1])
return 0;
if (arr[n - 1] >= arr[n - 2])
return n - 1;
for (int i = 1; i < n - 1; i++) {
if (arr[i] >= arr[i - 1] && arr[i] >= arr[i + 1])
return i;
}
}
int main()
{int n;cin>>n;int arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
cout << findPeak(arr, n);
return 0;
}
*****************************************************
PROBABILITY
1.
A bag contains 5 red, 6 green and 4 blue balls. Two balls are drawn at random. What is the probability
that none of the balls drawn in blue?
6/21
12/21
10/21
11/21
2.
Two dice are together. What is the probability that the sum of the numbers on the two faces is
multiple by 2 or 3?
1/3
3/3
2/3
4/3
3.
10 tickets are drawn successively with replacement from a bar containing 100 tickets numbered 201
to 300. The chance that all the tickets bear numbers divisible by 15 is:
(50/9)^10
(7/100)^10
(9/50)^10
(7/50)^10
4.
A bag contains 5 white and 6 black balls. Two balls are drawn at random. Find the probability that th
6/11
5/11
4/11
7/11
5.
A bag contains 20 black and 30 white balls. One ball is drawn at random. What is the probability that
the ball drawn is white
2/5
3/5
4/5
6/5
6.
Two cards are drawn from a well shuffled pack of 52 cards, without replacement. What is the
probability that one is red queen and other is a 6 number?
9/663
8/663
5/663
4/663
7.
What is the probability of getting a sum 10 from two throws of dice?
1/12
3/12
5/12
7/12
8.
In a throw of a coin, find the probability of getting a tail.
3/2
1/2
5/2
6/2
9.
In a box containing 80 bulbs 15 are defective. What is probability that out of a sample of 5 bulbs,
none is defective?
(13/16)^5
(19/20)^5
(12/13)^5
(16/13)^5
10.
Two dice are thrown simultaneously. What is the probability of getting two numbers whose product
is even?
5/4
1/2
5/14
3/4
11.
A card is drawn from a pack of 52 cards. The probability of getting a queen of diamond or jack of
club is:
4/26
2/26
3/26
1/26
12.
Three unbiased coins are tossed. What is the probability of getting atleast 2 tail?
1/2
7/2
3/2
6/2
13.
2 balls are drawn from basket containing 3 white, 4 red and 6 black balls one by one without
replacement. What is the probability that atleast one ball is red
13/7
7/13
12/7
7/12
14.
4 numbers are chosen at random from 1 to 30. The probability that they are consecutive is:
1/1015
5/2521
10/2357
8/2047
15.
Two cards are drawn together from a pack of 52 cards. The probability that one is a picture and on
20/221
8/221
10/221
12/221
16.
In a simultaneous throw of two dice, what is the probability of getting a total of 5 or 9?
3/9
4/9
5/9
2/9
17.
In a simultaneous throw of a pair of dice, find the probability of getting a total more than 8.
5/18
7/18
9/18
6/18
18.
A speaks truth is 90% and B in 95 % of the cases. In what percentage of cases are they likely to
contradict each other, narrating the same incident?
9/50
3/50
5/50
7/50
19.
Two cards are drawn at random from a pack of 52 cards. What is the probability that either both are
red or 2 numbers?
66/221
44/221
77/221
55/221
20.
In a simultaneous throw of two dice, what is the probability of getting a total of 6.
11/36
8/36
9/36
5/36
21.
A box contains 4 red, 5 green and 3 white balls. A ball is drawn at random. What is the probability
that the ball drawn is either red or green?
6/7
7/6
4/3
3/4
22.
From a pack of 52 cards, two cards are drawn together at random. What is the probability of both
five numbered card?
1/221
2/221
3/221
5/221
23.
An unbiased die is rolled. Find the probability of getting a odd number
3/2
1/2
5/2
3/4
24.
Probability of getting a number between 51 and 100, which is divisible by 1 and itself only is:
24/7
24/5
1/5
7/24
25.
In a simultaneous throw of two coins, the probability of getting both same kind is:
1/2
3/2
7/4
2/3
26.
A box contains 3 green, 5 yellow and 6 white marbles. Three balls are drawn at random. What is the
probability that they are not of the same color
200/364
153/364
123/364
333/364
27.
In a box there are 10 red, 12 blue and 5 green balls. One ball is picked up randomly. What is the
probability that it is neither red nor green?
5/9
6/7
5/7
4/9
28.
A box contains 8 white and 5 red balls. Three balls are drawn at random. What is the probability that
one ball is red and other two are white?
100/143
40/143
50/143
70/143
29.
From a well shuffled deck of 52 cards, 4 cards from suit are drawn at random. What is the probability
that all the drawn cards are of the same suit?
45/4165
46/4165
48/4165
44/4165
30.
Four cards are drawn at a time from a pack of 52 cards. What is the probability that all the drawn
cards are of the same color?
13c4 /52c4
2( 26c4)/52c
15c4/52c4
14C4 / 52C4
Post a Comment