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

INFEED

Hello World | PBT | DAILY TEST | 13 JUNE

 

 PBT RETEST OF 11 TH JUNE

 six playing cards

 

PROGRAMMING 

 
1.

Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block

is 1, compute how much water can be trapped between the blocks during the rainy season.

Input Format

First line of input contains n-the size of array. Next line of input contains n integers-the elements of the

array.

Constraints

3<=n<=10^5

0 <= Ai <= 10^8

Output Format

Print the total amount of water that can be trapped.

For example, in first sample test case:- Bars of input are {3,0,0,2,0,4}. So, Water trapped between 0th

bar and 1st bar=3 Water trapped between 1st bar and 2nd bar=3 Water trapped between 2nd bar and

3rd bar=1 Water trapped between 3rd bar and 4th bar=3 Total Water trapped=10.

 

 C++ CODE :

#include <bits/stdc++.h>

using namespace std;

int maxWater(int arr[],int n)

{

 int res=0;

 for(int i=1;i<n-1;i++)

 {

 int left=arr[i];

 for(int j=0;j<i;j++)

 left=max(left,arr[j]);

 int right=arr[i];

 for(int j=i+1;j<n;j++)

 right=max(right,arr[j]);

 res=res+(min(left,right)-arr[i]);

 }

 return res;

}

int main()

{

 int n;

 cin>>n;

 int arr[n];

 for(int i=0;i<n;i++)

 cin>>arr[i];

 cout<<maxWater(arr,n);

return 0;

}

 

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

2.

Problem Statement
«Polygon» is a system which allows to create programming tasks in a simple and professional way.
When you add a test to the problem, the corresponding form asks you for the test index. As in most
cases it is clear which index the next test will have, the system suggests the default value of the index.
It is calculated as the smallest positive integer which is not used as an index for some previously
added test.
You are to implement this feature. Create a program which determines the default index of the next
test, given the indexes of the previously added tests.
Input Format
The first line contains one integer n — the amount of previously added tests. The second line contains
n distinct integers a1, a2, ..., an-indexes of these tests.
Constraints
(1 ≤ n ≤ 3000) (1 ≤ ai ≤ 3000)
Output Format
Output the required default value for the next test index


 c++ Code :

#include <bits/stdc++.h>
using namespace std;
long long n,t,l,r,k,s,d,max1=0,b,c,mod=1e9+7;
long long a[100005];
map<long long,long long>m,p;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
 cin>>t;
 m[t]++;
}
for(int i=1;i<=3001;i++)
{
 if(m[i]==0)
 {
 cout<<i;
 break;
 }
}
return 0;

 

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

3.

Given a sorted array arr[] of distinct integers. Sort the array into a wave-like array and return it. In other
words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... (considering the
increasing lexicographical order).
Input Format
First line of input contains n-the size of array. Next line of input contains n integers-the elements of
array.
Constraints
1 ≤ n ≤ 10^6
0 ≤ Ai ≤10^7
Output Format
Print the array which should be sorted in wave like pattern

 

Python Code:

def sortInWave(arr, n):

     

    #sort the array

    
    

    # Swap adjacent elements

    for i in range(0,n-1,2):

        arr[i], arr[i+1] = arr[i+1], arr[i]
 
# Driver program
n=int(input())
arr = list(map(int, input(). split(' ')))

sortInWave(arr, len(arr))

for i in range(0,len(arr)):

    print(arr[i], end=" ")

 

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

  PROBABILITY

1.

A cricket club has 30 members of which only 10 can bowl. If the names of 30 members are put into a
box and 25 names are drawn at random, then the probability of obtaining 25 members team containing
exactly 8 bowlers is:
950/2639
900/2457
1250/2047
1005/2547
 

 

2.

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


3.

The probability that a number selected at random. From the set of numbers { 1,2,3,4............... 200} is a
cube is:
7/50
3/40
5/50
1/40
 

 

4.

A problem in Mathematics is given to 3 students whose chances of solving individuals are 1/3, 1/5 and
1/6. The probability that the problem will be solved atleast by one is: 3/7
4/9
9/8
5/9
7/9
 

 

5.

In a class 30% of students offered English, 20% offered Hindi and 10% offered both. If a student is
selected at random, what is the probability that he has offered English or Hindi?
5/2
3/5
2/5
5/3

 

6.

A bag contains 4 white and 3 black balls. 4 balls are successively drawn out and not replaced. One
probability that they alternately of different color?
25/3
6/35
3/25
35/6
 

 

7.

A person writes 4 letters and address on 4 envelops. If the letters are placed in the envelopes at
random, what is the probability that all letters are not placed in the right envelopes?
3/4
4/5
23/24
24/23

 

8.

Tickets numbered 1 to 30 are mixed up and then a ticket is drawn at random. What is the probability
that the ticket drawn has a number which is multiple of 3?
2/3
7/20
2/7
1/3
 

 

9.

 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


10.

In a competition A, B, and C are participation. The probability that A wins is twice that of B. The
probability that B wins is twice that of C. Then the probability that A losses is:
7/5
3/7
7/3
5/7
 

 

11.

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

 

12.

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

 

13.

A man and his wife appear in an interview for 2 vacancies in the same post. The probability of husband's
selection is (1/7) and the probability of wife's selection is (1/4). What is the probability that one of them
is selected?
28/9
9/28
3/28
28/3
 

 

14.

Bag A contains 4 red and 6 black balls and bag B contains 5 red and 4 black balls. One ball is drawn
from bag A and 2 from bag B. Find the probability that out of 3 balls drawn, two are black and one is
red?
2/5
5/2
3/5
5/3

 

15.

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

 

16.

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
 

 

17.

A person draws out 2 balls successively from a bag containing 8 red and 6 white balls. The probability
that atleast one of them will be red is:
45/91
6!*10!
76/91
91/76

 

18.

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
 

 

19.

 A box contains 20 electric bulbs, out of which 4 are defective. 3 are chosen at random from this box.
The probability that atleast one of these is defective, is:
29/57
57/27
27/57
57/29


20.

A bag contains 8 white, 7 red and 10 black balls. 6 balls are drawn one by one with replacement. What is
the probability that atleast one ball is white?
1-(25/17)^6
25!*15!
1-(17/25)^6
none

 

21.

A bag contains 10 white, 12 red and 8 black balls. If 5 balls are drawn one by one with replacement, what
is the probability that none is white?
(2/5)^5
(5/2)^5
(3/2)^5
(2/3)^5

 

22.

Out of 20 persons 16 can speak Hindi and 6 can speak English. If two persons are chosen at random,
then the probability that one person speaks Hindi only and other speaks both Hindi and English.
13/95
12/95
16/95
14/95
 

 

23.

4 persons are chosen at random from a group of 2 men, 4 women and 3 children. The chance that
exactly two of them are children, is:
5/14
11/21
22/11
11/22
 

 

24.

 In a class there are 8 boys and 5 girls. 3 students are selected at random. The probability that 2 girl and
1 boys are selected, is:
80/143
40/143
60/143
50/143


25.

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

 

26.

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
 


 

27.

In a lottery there are 15 prizes and 20 blanks. A lottery is drawn at random. What is the probability of
getting a prize?
7/3
5/7
3/7
6/7

 

28.

The letters of the word "NUMBER" are arranged in all possible ways. The chance that there are exactly 2
letters between B and E is:
5/7
7/5
1/5
3/5
 

 

29.

A combination lock on a suitcase has 3 wheels each labeled with 9 digits from 1 to 9. If an opening
combination is a particular sequence of 3 digits with no repeats, what is the probability of a person
guessing the right combination?
1/504
5/504
7/504
17/504

 

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

Previous Post Next Post