0% found this document useful (0 votes)
78 views55 pages

TCS Verbal, Numeric, Reasoning Ability Advanced Coding Material

The document contains 17 previous year questions from the TCS-NQT Verbal Ability Foundation Section exam. The questions cover topics like identifying errors in sentences, revising sentences, choosing the most appropriate option to fill in blanks, and selecting the most appropriate sentence for gaps in passages. The answers and explanations for each question are also provided.

Uploaded by

pradyumnatpo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views55 pages

TCS Verbal, Numeric, Reasoning Ability Advanced Coding Material

The document contains 17 previous year questions from the TCS-NQT Verbal Ability Foundation Section exam. The questions cover topics like identifying errors in sentences, revising sentences, choosing the most appropriate option to fill in blanks, and selecting the most appropriate sentence for gaps in passages. The answers and explanations for each question are also provided.

Uploaded by

pradyumnatpo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

TCS-NQT Verbal Ability Foundation Section Previous Year Questions

Q1) One part of the sentence below may contain may error. Identify the part. If there is no error,
choose "No error". Everyday life have become more complicated with the advancement in mobile
technology.

A. More complicated with the

B. Everyday life have become

C. No error

D. Advancement in mobile technology

Answer: Option B

Explanation: Since life is singular ‘has’ is the verb to be used instead of have.

Q2) The following three sentences can be revised into one better sentence. Choose the sentence that
is the best revision: (i) I was at the fair. (ii) I got lost. (iii) I got scared.

A. I am scared after I am lost at the fair.

B. I went to fair and got scared as I was lost.

C. I am lost at the fair so I am too scared.

D. I got lost at the fair and was scared.

Answer: Option D

Explanation: Since all the three parts talks about the past tense. The revised sentence should also be
in PAST.
So, options A and C are eliminated as they are in the simple present tense using ‘am’.

In between B and D. B is giving additional information – I went to the fair, which is never mentioned.
So the best revised sentence is option D.

Q3) In which of the following sentences does NOT use informal language?

A. Did you locate our office quite easily?

B. You will be working with different managers during your training.

C. We shall endeavour to inform you of the position in two weeks time.

D. Is there anything else you want to ask me?

Answer: Option B

Explanation: The sentence to be selected does NOT use informal means – the sentence should be a
formal sentence.

The most formal of all is option B

Q4) The lady _____ purse was lost lodged a complaint at the police station.

A. Who

B. Whose

C. Whom
D. Where

Answer: Option B

Explanation: “Whose” is a possessive adjective that describes that the lady owns the purse.

Q5) The final report on the project was ______ into three parts

A. Broken up

B. Broken off

C. Broken away

D. Broken out

Answer: Option A

Explanation: The phrase - break up indicates dividing something into smaller parts.

Q6) Some part of the sentence below may contain an error. Identify the part. If there is no error,
choose ‘No Error’.

The new computation algorithm combines scores with multiple measures of quantitative assessment

A. The new computation algorithm combines

B. scores with multiple measures


C. No error

D. of quantitative assessment

Answer: Option C

Explanation: Subject verb agreement is perfectly followed with a singular subject and singular verb.
So, no error in the sentence.

Q7) Some sentences are missing from the given text. Choose from the list (A-C) the most appropriate
sentence for each gap (1-2) in the text. There is one extra sentence that you do not need to use.

Albert Einstein always had a clear view of the problems of physics. 1._________________. He had a
strategy of his own and was able to visualize the main stages on the way to his goal.
2.__________________. He received the Nobel Prize in physics in 1921.

A. In 1919, Einstein and his wife, Mileva maric, were divorced

B. He also had the determination to solve them

C. Einstein regarded his major achievements as mere stepping stones for the next achievement

A. (1)-B, (2)-C

B. (1)-A, (2)-B

C. (1)-C, (2)-B

D. (1)-B, (2)-A

Answer: Option A

Explanation: In statement B, “solve them” – refers to solve the problems of physics.


So, the blank 1 should be statement B. Hence options B and C are eliminated.

Statement A does not fit well in blank 2.

Statement C fits well, since his major achievements led to his next achievement which was
mentioned next to the blank.

So, option is A.

Q8) Select the most appropriate option to fill in the blanks:

Children were quite sad when they did not see butterflies flitting _____ the flowers

A. In

B. With

C. Among

D. Between

Answer: Option A

Explanation: Flitting is flying.

Since butterflies are flying ____ the flowers.

With and between does not fit well.

In between options A and C.


Flying in the flowers is the most appropriate preposition.

Q9) One part of the sentence below may contain an error. Identify the error or choose “No Error”

The children are quick to grasp, isn’t it?

A. No error

B. Isn’t it?

C. The children are

D. Quick to grasp

Answer: Option B

Explanation: The question tag pronoun should be reflecting about the noun, that is mentioned.

The noun is children which is plural, so the pronoun and the verb must also be plurals.

SO, the right question tag is - aren’t they?

Error is in option B.

Q10) Select the most appropriate option

We have found that between Vinaya and Akruti, Vinaya makes _____ errors in her work

A. Largest
B. Smallest

C. Shortest

D. Fewer

Answer: Option D

Explanation: Since it is a comparison between two people, the word to be used is comparative
degree but not positive or superlative. The only comparative degree word is fewer, which is option D.

Q11) For the four sentences (S1 and S4) paragraph below, sentences S1 and S4 are given. From the
options P, Q, and R, choose the appropriate sentences for S2 and S3 respectively.

S1: My mother had been overweight since she was a child and lost weight only after she got married.

S2:

S3:

S4: There were no use crying to my grandmother as she was now absolved of her responsibilities

P: She started giving me lectures on the importance of meditation and breathing exercises.

Q: My food was regulated - she decided when, what and how much.

R: Her memory of overcoming severe problems of obesity kicked in and soon my weight and health
became her obsession.

A. RP
B. QR

C. PR

D. RQ

Answer: Option D

Explanation: Meditation and breathing exercises might not be much appropriate here to add or
mention. So, sentence P can be neglected. Hence options A and C which contain P are eliminated.

In between B and D, the sentences R and Q have cause and effect relationship.

Cause being R and effect being Q. So, the link is RQ.

Q12) One part of the sentence below may contain an error. Identify the error or choose “No Error”

One of the unreturned book was found in the parking lot.

A. he unreturned book

B. No error

C. was found in the parking lot.

D. One of

Answer: Option A

Explanation: It should be, One of the unreturned books. “One of” must always have a plural word,
which gives a meaning of “one of many”. Hence the sentence that has error is option A.
Q13) One part of the sentence below may contain an error. Identify the error or choose “No Error”

All the students of the class decided to head to the principal’s office to complain for the new
teacher’s misconduct

A. to head to the principal’s office

B. All the students of the class decided

C. to complain for the new teacher’s misconduct

D. No error

Answer: Option C

Explanation: “Complain against” must be the phrase instead of “complain for”.

So, the error is in option C

Q14) Read the following passage and fill in the blanks by selecting the most appropriate option

Mamallapuram, also called Mahabalipuram, is about fifty-five kilometres from the city of Chennai.
The East Coast Road takes you to this 1________ (missing) which is on the shore of the Bay of
Bengal. This 7th century city which was once a 2._____ seaport is now famous for its rock-cut shore
temples.

Blank 1. A. consequential B. mementitous C.historic D.fateful

Blank 2. A.frantic B. stuffed C.swamped D.busy

A. (1)-B,(2)-C
B. (1)-A,(2)-A

C. (1)-A,(2)-B

D. (1)-C,(2)-D

Answer: Option D

Explanation: Consequential – Important

Mementitous – important

Historic – famous or important in history

Fateful - having an important effect on the future

Frantic - extremely worried or frightened

Stuffed – packed or filled

Swamped – active or engaged.

Blank 1 – The sentence – “This 7th century city” talks about the city that was introduced in before
statement. Since they are giving an information saying 7th century, it must be “historic”. So, Historic
fits the best. With blank 1 as historic there is only one option C.

Q15) You are going to read Civilization. Choose from the list (A-C) the most appropriate sentence for
each gap (1-2) in the text. There is one extra sentence that you do not need to use.
Civilisation’s progress must be measured in proportion to man’s success in meeting the challenges of
nature. 1.____________________________. It is once a threat to the sustainable evolution of man.
2.___________________________. But if the current trend continues going on unchecked, the
future of life on earth will be endangered.

A. But the advancement in Science and Technology is, undoubtedly a mixed blessing

B. There has been an increase in the people's awareness of the consequences of such progress

C. We are bringing out industrial progress to make the world a better and more comfortable place to
live in

A. (1)- B, (2)- A

B. (1)- A, (2)- C

C. (1)- C, (2)- A

D. (1)- A, (2)- B

Answer: Option C

Explanation: “The current trend” talks about “the industrial progress to make the world better…”

So blank 1 must be sentence C. So, the only option is C.

Q16) One part of the sentence below may contain an error. Identify the error or choose “No Error”

Mrs. Diggle wanted her children to be hardworking, sincere and punctual

A. sincere and punctual


B. Mrs. Diggle wanted her

C. No error

D. Children to be hardworking

Answer: Option C

Explanation: There is no error in the sentence.

Q17) One part of the sentence below may contain an error. Identify the error or choose “No Error”

The soldiers, in an attempt of showing their loyalty towards their king,fought ruthlessly until the end
of the war

A. The soldiers, in an attempt of showing

B. fought ruthlessly until the end of the war

C. their loyalty towards their king

D. No error

Answer: Option D

Explanation: No error in the sentence.

Q18) The following sentence pair can be combined into one better sentence. CHoose the option that
contains the two sentences without changing the meaning:

My mother made me join seven different sports activities. At the time, I was just nine

A. My mother made me join seven different sports activities when I was just nine
B. Because I was nine, my mother made me join seven different sports activities

C. While I was nine my mother made me join seven different sports activities

D. Though I was 9, my mother made me join seven different sports activities

Answer: Option A

Explanation: The combined sentence should give a proper meaning of the sentences given in the
question.

Because, while and though are not appropriate to use when combining, since these words give
different meaning.

So only option is A.

Q19) One part of the sentence below may contain an error. Identify the error or choose “No Error”

He had been married with a doctor for five years

A. For five years

B. He had been married

C. No Error

D. With a doctor

Answer: Option D

Explanation: The correct sentence should be – He had been married to a doctor for five years.
So, error is option D.

Q20) Select the most appropriate option to fill in the blanks:

Shreya will keep working for you _____ you are respectful towards her.

A. For

B. As long

C. As long as

D. As soon as

Answer: Option C

Explanation: The only right phrase to be used is “as long as”

TCS NQT Numerical Ability (Foundation Section Previous Year Questions)

Q1) A man has to travel 50 km in two hours. He could cover 20 km in one hour and then had to
stop for 10 minutes for refueling. By what factor should he increase his speed with reference to
that during the first hour so as to be able to complete the journey as per schedule?

A. 1.2

B. 1.8

C. 2.4

D. 1.5

Answer: Option B
Explanation: Given that,
Total distance covered by man in 2 hours = 50km.
in first hour, he covers = 20km.
So,
Distance left to be cover = 50 - 20 = 30km.
Time left = 2 - 1 = 1 hour.
now, given that, he had to stop for 10 minutes for refuelling.
So,
Time left for travel = 1 hour - 10 min. = 60 - 10 = 50 minutes.
Therefore,
Distance to be covered now = 30km.
Time left = 50 minutes = (50/60) = (5/6) hours.
New speed = Distance/Time = 30/(5/6) = 30 * (6/5) = 36 km/h.
Hence,
Speed in first hour = 20km/h .
speed in second time = 36km/h.
Increased speed in factor = (36 /20) = 1.8 times. (Ans.)
So, he has to increased his speed 1.8 times in order to complete the journey as per schedule time.

Q2) What is the diameter in cm of a solid right circular cylinder whose height is 6 cm and the area
of the curved surface is five times the combined area of the two flat surfaces?

A. 3

B. 2.4

C. 1.2

D. 0.9

Answer: Option B
Explanation:
Q3) If n is an integer such that 1nn352 is a six-digit number exactly divisible by 24, What will be the
sum of the possible values of n?

A. 15

B. 27

C. 9

D. 21

Answer: Option A
Explanation: we know that,
If the sum of the digits of a number is divisible by 3, then the number is divisible by 3.
A number is divisible by 8 if the last three digits are evenly divisible by 8.
If the number is separately divisible by 3 and 8 then the number is also divisible by 24.
So, we can conclude that, if given 6 digit number is divisible by 24, it must be divisible by 3 and 8.
checking by 8 first we get: -
352/8 = 44 quotient, 0 remainder.
So, it is divisible.
now, in order to divisible by 3, sum must be divisible by 3.
So,
(1 + n + n + 3 + 5 + 2) / 3 = 0 remainder.
(11 + 2n) / 3 = 0 remainder.
Putting values of n now, we get,
if n = 0 => 11 /3 = Remainder not equal to 0.
if n = 1 => (11 + 2)/3 = Remainder not equal to 0.
if n = 2 => (11 + 4)/3 = Remainder equal to 0.
if n = 3 => (11 + 6)/3 = Remainder not equal to 0.
if n = 4 => (11 + 8)/3 = Remainder not equal to 0.
if n = 5 => (11 + 10)/3 = Remainder equal to 0.
if n = 6 => (11 + 12)/3 = Remainder not equal to 0.
if n = 7 => (11 + 14)/3 = Remainder not equal to 0.
if n = 8 => (11 + 16)/3 = Remainder equal to 0.
if n = 9 => (11 + 18)/3 = Remainder not equal to 0.
Therefore,
→ sum of Possible values of n = 2 + 5 + 8 = 15 (Ans.)

Q4) What is mean proportional (MP) between the MPs of (2/7 & 32/343) and (2 & 1/5000)?

A. 3/35

B. 4/35

C. 2/35

D. 2/175

Answer: Option B
Explanation: Let the MP of 2/7 and 32/343 be x
x = √(2/7)*(32/343)
= √(64/4901)
= (8/49)
Let the MP of 2 and 1/5000 be y
y = √(2)*(1/5000) = √1/2500 = 1/50
MP of x and y = √(8/49)*(1/50) = √8/2450
= √4/1225 = 2/35

Q5) How much percentage is (0.025% of 240% of 1.5) of 0.9?

A. 0.01

B. 10

C. 0.1

D. 1

Answer: Option C
Explanation: (0.025/100) * (240/100) * 1.5
= 1/4000 * 24/10 * 1.5
= 9/10000
Let x% of 0.9 be 9/10000
x% (0.9) = 9/10000
(x/100) (0.9) = 9/10000
x = (9/10000)*(100/0.9)
x = 0.1

Q6) The cost of filling a gas tank at a shop is Rs. 800. If the shopkeeper reduces the price by
15%.The number of his customers increases by 30%. By what % did his revenue
decrease/increase.?
A. 10.5%
B. 10%
C. 8%
D. 12.5%
Answer: Option A
Explanation: Let initial number of customer's are x .
So,
Initial cost of filling a gas tank = Rs.800
Initial number of customer's = x
then, Initial total revenue = 800 * x = Rs. 800x
Now,
New cost of filling a gas tank = 15% reduced = (85 * 800)/100 = Rs. 680
New number of customer's = 30% increases = (130 * x)/100 = 1.3x
then, New total revenue = 680 * 1.3x = Rs. 884x
therefore,
Revenue increased by = 884 - 800 = Rs. 84x
hence, Revenue increased in % = (84x * 100)/800x = 10.5%
Q7) Rahl takes a sum of Rs. 2310 as a loan. He has to repay this in two equal annual installments. If
the rate of interest is 20% compounded annually, what percent of the principal amount taken
by Rahul is the total interest paid by him.
A. 20%
B. 40.9%
C. 130.9%
D. 44%
Answer: Option D
Explanation:

Q8) Two numbers are in the ratio of 3:5 . If 3 is added to the first number and 9 is added to the 2nd
number, their ratio becomes 4:7. The sum of the original numbers is.

A. 120

B. 150

C. 105

D. 135

Answer: Option A
Explanation:

Q9) Ankush bought (x+2) apples at the rate of Rs. 12 each. One apple got rotten during
transportation and he sold all the remaining apples for Rs. 300. If the percentage profit made
by Ankush in the whole transaction is 25%, find the number of apples sold by Ankush.

A. 19

B. 15

C. 10

D. 12

Answer: Option A
Explanation: Here it is given that Ankush bought (x+2) apples at the rate of Rs. 12 each.
So total cost price = Rs 12(x + 2)
Now one apple got rotten during transportation
So, number of apples sold = x + 2 - 1 = x + 1
Total selling price = Rs 300
Profit percentage = 25%
So, by the given condition,
12(x+2) * 125/100 = 300.
X = 18
Hence the number of apples sold by Ankush
= 18 + 1
= 19

Q10) An article is marked 36% above its cost price. A discount of 10% is offered on the marked
price. Later on, the article was sold by giving another discount of Rs.12.60. If there is a profit of
15.4%, the marked price (in Rs.) of the article is:
A. 245
B. 243
C. 220.30
D. 244.80
Answer: Option D
Explanation: Let CP of article = Rs. 100x
MP = 36% above CP = (136 * 100x)/100 = Rs. 136x
Discount = 10%
SP = MP * (100 - D)/100 = (136x * 90)/100 = Rs. 122.4x
now,
Another discount = Rs.12.60
SP after another discount = Rs. (122.4x - 12.6)
According to the question,
Total Profit = 15.4%
122.4x - 12.6 = (100x * 115.4)/100
122.4x - 12.6 = 115.4x
7x = 12.6
x = 1.8
therefore,
MP of article = 136x = 136 * 1.8 = Rs. 244.80

Q11) The ratio of 25% of x to 65% of y to 70% of z is 5:26:15. If one sixteenth of their sum(x,y and z)
is equal to 10. What is the value of X-2Y+3z?

A. -20

B. -10

C. 10

D. 0

Answer: Option D
Explanation: 25% of x: 65% of y : 70% of z = 5 : 26 : 15
(25 * x)/100 : (65 * y)/100 : (70 * z)/100 = 5 : 26 : 15
5x:13y:15z = 5:26:15
5X = 5a
x=a
and 13Y = 26a
Y = 2a
and, 15Z = 15a
Z=a
also,
(1/16) (x + y + z) = 10
(x + y + z) = 160
a+2a+a = 160
a=40
therefore, x = 40, Y = 80 and Z = 40
(x - 2y + 3z) = 40 -160 +120 = 0

Q12) A boat travels 12 km downstream and 6 km upstream in 3 hours. The same boat takes fifty
percent extra time to cover 10 km downstream and 16 km upstream. If the same boat travels 20
km downstream and z km upstream in 4 hours find z.
A. 9km
B. 7.5km
C. 8km
D. 4.5km
Answer: Option D
Explanation:

Q13) The savings of surekha are equal to 40% of her expenditure. If her income increases by 20%
and the expenditure increases by 40%, her savings decreases by:

A. 20%

B. 30%

C. 50%

D. 10%

Answer: Option B
Explanation: Let saving = 40, expenditure = 100 hence income = 140
Income increases by 20% = 168, expenditure increases by 40% = 140, saving = 28
% decrease = 40-28 /40 * 100 = 30 %

Q14) The shopkeeper sold some chairs for Rs. 3240 and made a profit of 20%.What was the profit
percentage if he had sold chairs for Rs. 2781????????

A. 4.25%

B. 3%

C. 4.5%

D. 3.25%

Answer: Option B
Explanation: Profit = 20%
Hence 120% of cost price = 3240
Cost price = 2700
New selling price = 2781/- , profit = 81
% profit = 81 / 2700 * 100 = 3%

Q15) If 20% apple from a cart are rotten and the remaining apple are sold at 20% discount the
seller gets 92%profit on the cost price of the whole cart by what percent above the cost price
Has the seller marked up the apples?

A. 180%

B. 250%

C. 280%

D. 200%

Answer: Option D
Explanation: Let there be 100 apples with a cost price of 100 and cost amount=100*100=10000
Sale amount at 92% profit over all=10000*192/100=19200
Number of rotten apples at 20%=20/100*100=20
Number of saleable apples =100-20=80
Sale price at 92% profit over all =19200/80=240
Marked price to allow discount at 20%=240/80*100=300
Mark up=mp-cp=300–100=200
Percentage of mark-up=200/100*100=200%

Q16) Out of 80 students 45%, students passed in Mathematics and 60% students passed in English.
If 35% students failed in both the subjects, how many students passed in both the subjects?

A. 24

B. 28

C. 32

D. 20

Answer: Option C
Explanation: 45% of 80 = 36
60% of 80 = 48
Total passed = 80 - 35% of 80 = 80 - 28 = 52
passed in both = 48+36-52= 32

Q17) 50 workers can construct a bridge in 40 days by working 8 hrs per day. But they completed 30
days and completed only half of the work. How many more workers are needed to complete the
work on time by working 10 hrs per day?

A. 65
B. 50

C. 60

D. 70

Answer: Option D
Explanation: Total Days = 40
Days gone = 30
Days left = 40 - 30 = 10
number of hours per day = 10 hrs
as work is same
M1*H1*D1 = M2*H2*D2
50*8*30 = (50+X) * 10 * 10
X = 70

Q18) The ratio of the speed of a bus and a car is 2:5. The car covers a distance of 280 km in some
time and the bus covers a distance of “d” km less in the same time. What is the distance covered
by the bus?

A. 112 km

B. 144 km

C. 168 km

D. 132 km

Answer: Option A
Explanation: Speed of bus = 2x km/hr
Speed of car = 5x km/hr
Distance = Speed * time
280 = 5x * T
distance covered by the bus = y
y = 2x * T
280/y = 5/2
y = 280 * 2/ 5
y = 112
distance covered by the bus = 112 km

Q19) The sum of the present ages of Ajay and his wife Sushma is 82 years. Sushma’s present age is
28 years more than Sashank, her son. If Sashank’s present age is 12 years, what will be the sum of
ages of Sashank and his father after 4 years?

A. 56 years

B. 60 yeras

C. 62 years
D. 58 Years

Answer: Option C
Explanation: Age of Ajay + Sushma = 82
Shashank = 12 , hence Sushma = 28+12 = 40
Ajay = 82-40 = 42
Sashank after 4 years = 16
Ajay after 4 years = 46
Sum = 16+46 = 62 years

TCS NQT Advanced Quantitative Ability (Advanced Section) Previous year Questions

Q1) A sum of Rs 7500 amounts to Rs 9075 at 10% p.a in a certain time, when the interest is
compounding annually.

What is the amount in (Rs) of the sum at the same sum at the same rate for 6/5th of the earlier
time.

A. 9412

B. 9427

C. 9680

D. 9580

Answer - Option B
Explanation: From condition 1,
Q2) The average weight of some students in class is 62kg. If 8 students of average weight 55kg
leave the class and13 students of average weight 65 kg joins the class, then the average weight of
remaining students in the class is 63.9 kg. The number of students in the class initially was?

A. 45

B. 55

C. 40

D. 50

Answer - Option A
Explanation: We can solve this question easily using linear equations and the concept of average.
Let the number of students initially present in the class be = x
then the weight of all the students = 62x (? total = avg × no. of things)
when 8 students leave the class, the weight of the remaining
students = 62n - 8(55)
and when other 13 students join the class, the weight of all students =
62n - 8(55) + 13(65) = 63.9 (n - 8 + 13)
62n = 63.9(n+5) + 440 - 845
62n - 63.9n = 319.5 - 405
- 1.9n = -85.5
x = 45
∴ The total number of students in the class initially were 45.

Q3) Ramesh can complete a work in 20 days. Mohan is 66.67% as efficient as Ramesh. Mohan and
Ramesh work together. Ramesh leaves after working for some days. The remaining work is done by
Mohan in 10 days. After how many days did Ramesh leave the work?

A. 10 days

B. 6.5 days

C. 8.5 days

D. 8 days

Answer - Option D
Explanation: Given,
Ramesh completes work in 20 days
Let the Total work to be completed = 1 (1 unit)
So,
Ramesh can complete (1/20) part of work in 1 day
Given,
Mohan is 66.67% as efficient as Ramesh
i.e., If Ramesh completes X part of work in 1 day, then Mohan completes 2X/3 part of work in 1 day.
Here, Ramesh completes (1/20) part of work in 1 day
So, Mohan can complete (2/3)*(1/20) = (1/30) part of work in 1 day
Mohan can complete work in 30days
Let D be the days Ramesh has worked i.e., after D days Ramesh left the work.
Both Ramesh and Mohan can complete (1/20+1/30) part of work in 1 day.
In D days Ramesh and Mohan can complete
D*(1/20+1/30) part of work
In 10 days Mohan can complete
10*(1/30) part of work
We have,
D*(1/20+1/30) + 10*(1/30) = 1
L.C.M of (20,30) = 60
D*(3+2) + 10*2 = 60
5D + 20 = 60
5D = 40
D=8
Therefore, after 8 days Ramesh left the work

Q4) When a number x is divided by 9, the remainder is 6. When the same number is divided by 21,
the remainder is 12. If the x lies between 250 and 400, then what is the sum of all possible values
of x.?
A. 1107

B. 855

C. 1044

D. 666
Answer - Option B
Explanation:

x = 9A + 6
x = 21B + 12
9A + 6 = 21B + 12
9A = 21B + 6
3A = 7B + 2
B = 1, A = 3 => x = 33
B =4, A = 10 => x = 96
B = 7, A = 17 => x = 159
and so on x = 222, 285, 348, 411
x between 250 and 400
So, x can be 285, 348
Sum = 285 + 348 = 633
sum of all possible values of x is 633.

Q5) A bag contains x+5 yellow balls, 2x+1 blue balls and some red balls. If two balls are drawn one
after another from the bag without replacement, then the probability of getting a red and blue ball
is 1/6. The total balls in the bag is 4(x+2). Find the number of red balls.

A. 8

B. 4

C. 6

D. 5

Answer - Option D
Explanation: Yellow balls are = x + 5
Blue balls are = 2x + 1
Red balls =?
Total balls = 4(x + 2) = 4x + 8, So red balls are = x + 2.
Find value of x, to answer how many red balls are there.
Given, two balls were selected and the probability of getting a red and blue is 1/6.
From this,
{(x+2)C1 * (2x+1)C1}/(4x+8)C2 = 1/6
Solving above equation gives x = 2.
So total red balls are = x +2 = 2+2 = 4. Option B

Q6) The taxi charges in a city consist of a fixed charge together with the fixed charge for the
distance travelled in kilometers. When a person travels 72 km he pays 1107. He pays Rs. 898 for
travelling 55 km. What will he have to pay for travelling 45 km?
A. Rs. 826

B. Rs. 740

C. Rs. 693

D. Rs. 774

Answer - Option D
Explanation: Let, fixed charged be = Rs. X
And charge per km = Rs. Y
1st journey, X + 72y = 1107
2nd journey, X + 55y = 898.
Solving both Y = Rs. 12.3.
Substituting Y in any one of the equations gives, X = Rs. 221
Then for 3rd journey, X + 45y = 221 + 45*12.3 = 774

Q7) C can complete the work alone in 60 days. A and B take 40% and 75% more time than C. The
work was started by A and B, and C worked with A on every third day, In how many day the work
will be completed.

A. 16(4/5)

B. 48(1/4)

C. 16(1/4)

D. 48(4/5)

Answer - Option D
Explanation: C can complete the work alone in 60 days.
A can complete work in 60 + (40/100)60 = 84 days
B can complete work in 60 + (75/100)60 = 105 days
Work Done in 3 Days =
3 * (1/84) + 1/105 + 1/60 = (15 + 4 + 7)/420 =26/420
= 13/210
Work done in 16 * 3 = 48 days
= 16 * 13/210 = 208/210
Work left = 2/210 = 1/105
1/105 Work done by A in (1/105)/(1/84) = 4/5 day
Hence work will be completed in = 48 4/5 Days

Q8) A and B start from the same point and cover equal distances. A travels by car and covers the
distance in 3 hours with a speed of 50 km/h. The B travels by bus which stops for 10 mins after
covering 10 kms. In how much time will the bus reach the destination if the speed of the bus is
40% less than the speed of the car?

A. 6 h 40 min

B. 7 h
C. 7 h 30 min

D. 7 h 20 min

Answer - Option D
Explanation: Distance = speed × time
total distance = 50km×3hr= 150km
speed of bus is
50 - 40% of 50 = 30km/hr
time taken by bus without stopping
150/30 =5hr
since bus stops for 10 min at each 10km
150km/10km = 15 stops
but last stop we are not considering
because its the destination.
14 stops ×10 min =140 min
so total time spent will be 5hr + 140min i.e.,
7hr 20min

Q9) A sum when lent at the rate of 15% p.a.simple interest for x years amounted to 17,600.When
the same sum was lent at the rate of 18% p.a. The Simple interest for (x+2.5) years, it amounted
for 24,320. The value of x and the sum, respectively are?

A. 2.5 and 12500

B. 2.5 and 12800

C. 2 and 12500

D. 3.5 and 12800

Answer - Option B
Explanation:

Q10) Raj sold his bat at x% profit after giving a discount of x%. The marked price was Rs. 2,400
more than the cost price. And the selling price was Rs. 900 more than the cost price. Find the value
of 4x.?

A. 100

B. 50
C. 40

D. 200

Answer - Option A
Explanation: Selling price = 900 + C.P
Mark price = 2400 + C.p
Discount = M.P – S.P = 1500
Profit = S.P – C.P = 900
X% of C.p = 900
X% of MP = 1500
X% of ( 2400 + CP ) = 1500
X% of 2400 + x% of cp = 1500
X% of 2400 + 900 = 1500
X% of 2400 = 600
X = 25
Value of 4x = 100

Q11) If the average of five consecutive odd number is 27, then what will be the sum of the largest
number and the average?

A. 63

B. 62

C. 61

D. 58

Answer - Option D
Explanation: Let numbers are X, X+2, X+4, X+6, X+8
Average = sum /5
Sum = 5X + 20
5X +20 = 27*5
X = 23
Largest number = X+8 = 23+8 = 31, average = 27 sum = 31+27 = 58

Q12) A Car covers the distance between two points in 45minutes. If the speed of the car is reduced
by 5km/hr, the time taken to cover the distance increases to 48minutes. What is the distance
between the two points?

A. 55km

B. 50km

C. 60km

D. 45km

Answer - Option C
Explanation: Let distance = X km
And speed = Y km/hr
A Car covers the distance between two points in 45minutes
X/Y = 45/60 hrs
x/y = ¾
4x = 3y
Y = 4x/3
If the speed of the car is reduced by 5km/hr, the time taken to cover the distance increases to
48minutes
X / (y-5) = 48/60
X / (y-5 ) = 4/5
5x = 4y – 20
Sub Y = 4x/3 value of X = 60km

Q13) A Sum of money, when invested at 20% interest per annum, compounded half-yearly,
amounts to a total of Rs.1,331 after a year. What is the sum of money that had been
invested????????

A. 1,120

B. 1,110

C. 1,100

D. 1,125

Answer - Option C
Explanation:

Q14) A shopkeeper bought a lamp at rs.1200 and the ratio of its cost price and marked price was
3:5. it was said after two successive discount of 30% and 18% and incurred a loss or profit of x%.
Find x.

A. 4 2/3 profit

B. 4 2/3 loss

C. 4 1/3 loss

D. 4 1/3 profit

Answer - Option C
Explanation: C.P = 1200
C.P : M.P = 3:5
Hence M.P = 2000
After 1st discount of 30% on 2000 = 600 will be reduce
M.P = 1400 2nd discount of 18% of 1400 = 252 will be reduced
S. P = 1148
LOSS = 1200 – 1148 = 52
% loss = 52 / 1200 * 100 = 4(1/3)loss %

TCS-NQT Reasoning Ability (Foundation Section Previous Year Questions)


Q1) There are five rods K, L, M, N, and O. The weight of O is twice the weight of L. The weight of L
is equal to the weight of K and M taken together. The weight of M is twice the weight of K. The
weight of N is thrice the weight of M. If the weight of N is 90 kg. What will be the weight of
O?

A. 105 kg

B. 60 kg

C. 120 kg

D. 90 kg

Answer: Option D
Explanation: N = 90
N is thrice the weight of M
3M = N
M = 30
M is twice of K
M = 2K
K = 15
L = K+M = 45
O is twice of L
O = 2L = 90

Q2) Which is the wrong term in the following series? CMQ, FPT, JTX, OYC, UFI

A. FPT

B. OYC

C. JTX

D. UFI

Answer: Option D
Explanation: The incorrect term in the series is UFI. (Option D)
The first two terms, CMQ and FPT.
The alphabets between C and F are 2 (D, E).
The alphabets between M and P are 2 (N, O).
The alphabets between Q and T are 2 (R, S).
Now the second and third terms, FPT and JTX.
The alphabets between F and J are 3 (G, H, I).
The alphabets between P and T are 3 (Q, R, S).
The alphabets between T and X are 3 (U, V, W).
Similarly, third and fourth terms, JTX, and OYC.
The alphabets between J and O are 4 (K, L, M, N).
The alphabets between T and Y are 4 (U, V, W, X).
The alphabets between X and C are 4 (Y, Z, A, B).
By comparing the last two terms, OYC and UFI, we found that,
The alphabets between O and U are 5 (P, Q, R, S, T).
The alphabets between Y and F were found to be 6 which does not satisfy the series.

Q3) In a certain code,

A % B means 'A is the brother of B',

A & B means 'A is the mother of B',

A @ B means 'A is the daughter of B',

A $ B means 'A is the father of B' and A # B means 'A is the sister of B'.

If K $ Z % U & H # N @ T, how is T related to U?

A. Sister

B. Husband

C. Wife

D. Brother

Answer: Option B
Explanation: K $ Z % U & H # N @ T
K is father of Z, Z is brother of U, U is mother of H, H is sister of N, N is daughter of T
U is mother of H& N, T is father of N
Hence T is husband of U.

Q4) Five teachers P, Q, R, S and T teach a group of students in sequence between 9 and 2 pm. Each
teacher teaches for one hour. Q takes the first class. S teaches just after T, R teaches before P and T.
Who takes the second class from 10 am to 11 am?

A. S

B. R

C. P

D. T
Answer: Option B
Explanation: Q takes first class from 9.00 a.m. to 10 a.m.
S teaches just after T.
R teaches before P and T.
It means R teaches before P, T and S.
Hence sequence in which the teachers take class is as follows:
Q → R → P → T → S.
Hence R will be second to take class from 10 a.m. to 11 a.m.

Q5) Given below is a question followed by two statements. I and II, each containing some
information. Which of the following statements is/are sufficient to answer the question? How is A
related to C? Statements: I. A is the wife of B and B is the brother of C. II. C is the son of D.

A. Both I and II together are not sufficient

B. Statement I alone is sufficient.

C. Statement II alone is sufficient

D. Both I and II together are sufficient.

Answer: Option B
Explanation: From I. A is the wife of B and B is the brother of C.
A is sister -in – law for C
From II, we can’t find the relation between A&C , hence option B

Q6) Find the wrong term in the letter cluster series given below:

In DRTO. JXZU, GUWR, MAOX, JXZU

A. JXUZ

B. JXZU

C. MAOX

D. GUWR
Answer: Option C
Explanation: the difference between 1st terms , 2nd, 3rd & 4th terms are like +6,-3,+6,-3 only term that
doesn’t follow the rule is MAOX

Q7) In each of the five pairs of letter-clusters, the letter in the second term are a rearranged/
transformed form of the letters has been put together in a particular pattern. In which two pairs,
has the transformation been done in the same way?
A. PLANT: PLZMG
B. MANGO: MAMTL
C. BLACK: BLBDP
D. TABLE: ATLBE
E. CHEER: HCREE
A. D and A
B. C and D
C. B and C
D. A and B
Answer: Option D

Q8) Statements:
Some drills are drugs
No drug is a dam
No drill is a laker
Conclusions:
I. Some lakers are drugs
II. Some dams are drills
A. If neither conclusion I nor II follows
B. If only conclusion II follows
C. If either conclusion I or conclusion II follows
D. If only conclusion I follows
Answer: Option C
Explanation: either conclusion I or conclusion II follows as per the venn diagram

Q9) Find the wrong term in the given series


IWLZ,NSOU,SOTQ,XKAM,CGJI
A. NSOU
B. IWLZ
C. CGJI
D. XKAM
Answer: Option B
Q10) Given below is the question followed by two statements ,I and II each containing some
information.Decide which if the statement(s) is/are sufficient to answer the question.
Five persons - A,B,C,D and E sit around a circular table , facing the centre not necessarily in that
order .Who sits second to the right of D?
I. A sits the immediate right of E, who is not a neighbour of D.
II. B is to the immediate left of D.

A. If only statement II is sufficient to answer the question.


B. If the data in both the statement I and II together are necessary to answer the question.
C. If the data either in statement I alone or in statement II alone is sufficient to answer the question.
D. If only statement I id sufficient to answer the question.
Answer: Option B
Explanation: By using both I & II

Q11) Five persons A,B,C,D and E are comparing the number of books which they have bought
recently. A bought more number of books than C and E, but not the highest. B bought more
number of books than exactly one person. Then which of the following bought the highest number
of books?

A. C

B. D

C. B

D. E

Answer: Option B
Explanation: A > C& E
B is in 4th position
And a is more than c & e, and a is not the highest so only possibility for the 1st position is D

Q12) In a certain code, if:


J@K means j is k’s daughter.
J%K means j is k’s wife.
J + K means K is j’s father.
J / K means K is J’s mother.
F@R%I/E%N
How is R related to N in the given expression?

A. Mother-in-law
B. Son-in-law
C. Daughter-in-law
D. Mother
Answer: Option C

Q13) Among P,Q,R,S and T , Q is the second tallest and S is immediately taller than the shortest. R
is neither tallest nor the shortest. Who among them is in the middle when they stand in the order
of their heights?

A. R

B. P

C. S

D. T

Answer: Option A
Explanation: From the given statement, the descending order of heights is :__, Q,__, S,__.
From II, we have the order: _, Q, R, S,__. Thus, R is in the middle.

Q14) Given below is a question followed by two statements I and II, Decide which of the
statements is/are sufficient to answer the question.
What is the color of human blood?
Statements:
I. Red is called white and white is called yellow.
II. Yellow is called pink and pink is called green.
A. Statement II alone is sufficient
B. Either statement I alone or II alone is sufficient.
C. Statement I alone is sufficient.
D. Both statements I and II, are necessary.
Answer: Option C
Explanation: Only I is sufficient to identify the answer, Red is called white

Q15) Given the below question followed by two statements 1 and 2, each containing some
information. Decide which of the statements is /are sufficient to answer the question.
What is the height of triangle ABC?
1. The height and base of triangle ABC are in the ratio of 6:5.
2. The area of triangle ABC is 60 sq. cm, its perimeter is 36cm and its base is 5/18th of the The
perimeter of the triangle.
A. The data given in both statements 1 and 2 together is not sufficient to answer the question.
B. The data in either statement 1 alone or in statement 2 alone is sufficient to answer the question.
C. The data in statement 2 alone is sufficient to answer the question while statement 1 is not alone
sufficient to answer the question.
D. The data in statement 1 alone is sufficient to answer the question while statement 2 is not alone
sufficient to answer the question.
Answer: Option C
Explanation: By using 2. The area of triangle ABC is 60 sq. cm, its perimeter is 36cm and its base is
5/18th of the perimeter of the triangle.
Base = 5/18th of perimeter = 5/18 * 36 = 10cm
Area = ½ * base * height
60 = ½ * 10 * height
Height = 12cm

Q16)Sohan and Saurabh are brothers. Tanya and Tashima are sisters. Saurabh’s father is the only
son-in-law of Tanya’s mother’s mother. How is Tasima related to Sohan’s father ?
‘#’ is sister-in-law, ‘>’ is daughter, ‘<’ is granddaughter, and ‘@’ is sister?
A. #
B. >
C. <
D. %
Answer: Option B
Explanation: Saurabh’s father is the only son-in-law of Tanya’s mother’s mother
Hence saurabh’s father is married to Tanya’s mother
Tanya and saurab are brothers and sister
Tasima will be daughter to sohan’s father.

Q17) Read the given information carefully and answer the following questions
I. ‘A#B’ means ‘A’ is the mother of ‘B’
II. ‘A*B’ means ‘A’ is the father of ‘B’
III. ‘A&B’ means ‘A’ is the brother of ‘B’
IV. ‘A%B’ means ‘A’ is the sister of ‘B’
Which among the following expression shows that R is the maternal uncle of T?
A. P&Q*R#S#T
B. P#Q*R%S#T
C. P#Q*R*S#T
D. P%Q*R&S#T
Answer: Option D
Explanation: Going through options only D satisfy
P%Q*R&S#T
P is the sister of Q
Q is father of R
R is brother of S
S is mother of T
Hence, R is maternal uncle of T

Q18) Given below is the question followed by three statements, I II and III, each containing some
information. Decide which of the given statement is CORRECT?
The question consists of three statements numbered I, II and III, given below it.You have to decide
whether the data provided in the statements are sufficient to answer the question.
Eight people P, Q, R, S, T, U, V, and W were ranked based on their weights.Who is the 4th lightest
person?
I. U is heavier than only two persons. T is heavier than U but lighter than P , who is lighter than only
three persons.
II. R is heavier than P but lighter than Q.S is heavier than V.
III. P is heavier than S , who is lighter than U.
A. Data are given in all statements I, II, and III together are required to answer the question.
B. Data given in both statements I and II together are required to answer the question.
C. Data given in statements I and III together are required to answer the question.
D. Data given in statement I alone is required to answer the question.
Answer: Option D
Explanation: Only I is sufficient U is heavier than only two persons. T is heavier than U but lighter
than P , who is lighter than only three persons.
U will be in 6th place
P will be in 4th place
T will be in 5th place

Q19) Statements:
All taps are mats.
All cats are rats
All mats are rats.
Conclusions:
I. All cats are mats.
II. Some rats are taps.
III. Some taps are cats is not a possibility.
IV. All taps are rats.
A. Only IV follow
B. Only II and IV follow
C. Only I, III and IV follow
D. All follow
Answer: Option B
Explanation: As per Venn diagram only II & IV follows
Q20) Eight persons A, B, C, D, E, F. G, and H are sitting around a square table. All of them are facing
towards the center, Only one person sits on each of the sides and only one person sits on each of
the corners. Four of them sit on the sides and four of them sit on the corners. C is sitting 3rd to the
left of B, who sits on aside. D is sitting opposite to H, who is sitting 3rd to the right of B. A is sitting
2nd to the right of G. G is not sitting opposite to either E or F. F is not an immediate neighbor of H.
Who among the following is sitting opposite to A?

A. F

B. B

C. E

D. C
Answer: Option C
Explanation:

TCS NQT Advanced Coding Previous Year Questions


Q1) Given an array of integers where every element appears even number of times except one
element which appears odd number of times, write a program to find that odd occurring element
in O(log n) time. The equal elements must appear in pairs in the array but there cannot be more
than two consecutive occurrences of an element.

For example :

232
It doesn't have equal elements appear in pairs

1122233

It contains three consecutive instances of an element.

22311

It is valid and the odd occurring element present in it is 3.

Enter only valid inputs.

Sample Input :

22311

Sample Output :

3
Solutions:
C Language
#include <stdio.h>

int main()
{
int n; scanf("%d",&n);
int arr[n];
for(int i=0 ; i<n ; i++){
scanf("%d",&arr[i]);
}
int left=0,right=n-1,mid,pre,nxt;
if(arr[0] != arr[1]){
printf("%d ",arr[0]);
}
else if(arr[n-1] != arr[n-2]){
printf("%d ",arr[n-1]);
}
else{
while(left <= right){
mid = ((right-left)/2)+left;
pre = mid-1;
nxt = mid+1;
if((arr[pre] != arr[mid]) && (arr[nxt] != arr[mid])){
printf("%d ",arr[mid]);
break;
}
else if(mid%2==0){
if(arr[pre] == arr[mid])
right = mid - 1;
else
left = mid + 1;
}
else{
if(arr[pre] == arr[mid])
left = mid + 1;
else
right = mid - 1;
}
}
}
return 0;
}

C++
#include <iostream>
#include <vector>
using namespace std;

int main()
{
int n; cin >> n;
vector<int> v(n);
for(int i=0 ; i<n ; i++){
cin >> v[i];
}
int left=0,right=n-1,mid,pre,nxt;
if(v[0] != v[1]){
cout << v[0];
}
else if(v[n-1] != v[n-2]){
cout << v[n-1];
}
else{
while(left <= right){
mid = ((right-left)/2)+left;
pre = mid-1;
nxt = mid+1;
if((v[pre] != v[mid]) && (v[nxt] != v[mid])){
cout << v[mid];
break;
}
else if(mid%2==0){
if(v[pre] == v[mid])
right = mid - 1;
else
left = mid + 1;
}
else{
if(v[pre] == v[mid])
left = mid + 1;
else
right = mid - 1;
}
}
}
return 0;
}

JAVA
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for(int i=0 ; i<n ; i++){
arr[i] = sc.nextInt();
}
int left=0,right=n-1,mid,pre,nxt;
if(arr[0] != arr[1]){
System.out.print(arr[0]);
}
else if(arr[n-1] != arr[n-2]){
System.out.print(arr[n-1]);
}
else{
while(left <= right){
mid = ((right-left)/2)+left;
pre = mid-1;
nxt = mid+1;
if((arr[pre] != arr[mid]) && (arr[nxt] != arr[mid])){
System.out.print(arr[mid]);
break;
}
else if(mid%2==0){
if(arr[pre] == arr[mid])
right = mid - 1;
else
left = mid + 1;
}
else{
if(arr[pre] == arr[mid])
left = mid + 1;
else
right = mid - 1;
}
}
}
}
}

PYTHON
n = int(input())
a = list(map(int,input().split()))
left=0
right=n-1
if a[0] != a[1]:
print(a[0])
elif a[n-1] != a[n-2]:
print(a[n-1])
else:
while left <= right:
mid = ((right-left)//2)+left
pre = mid-1
nxt = mid+1
if (a[pre] != a[mid]) and (a[nxt] != a[mid]):
print(a[mid])
break
elif mid%2==0 :
if a[pre] == a[mid] :
right = mid - 1
else :
left = mid + 1
else :
if a[pre] == a[mid] :
left = mid + 1
else :
right = mid - 1;

Q2) Given an array of integers and a sum, the task is to count all subsets of given array with sum
equal to given sum.
Input :
The first line of input contains an integer T denoting the number of test cases. Then T test
cases follow. Each test case contains an integer n denoting the size of the array. The next line
contains n space separated integers forming the array. The last line contains the sum.
Output :
Count all the subsets of given array with sum equal to given sum.
NOTE: Since result can be very large, print the value modulo 109+7.
Constraints :

1<=T<=100

1<=n<=103
1<=a[i]<=103
1<=sum<=103
Example :
Input :
2
6
2 3 5 6 8 10
10
5
12345
10
Output :
3
3
Explanation :
Testcase 1: possible subsets : (2,3,5) , (2,8) and (10)
Testcase 2: possible subsets : (1,2,3,4) , (2,3,5) and (1,4,5)

Solutions:
C++
#include <bits/stdc++.h>
using namespace std;

void printBool(int n, int len)


{

while (n) {
if (n & 1)
cout << 1;
else
cout << 0;

n >>= 1;
len--;
}

while (len) {
cout << 0;
len--;
}
cout << endl;
}

void printSubsetsCount(int set[], int n, int val)


{
int sum;
int count = 0;
for (int i = 0; i < (1 << n); i++) {
sum = 0;

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

if ((i & (1 << j)) > 0) {


sum += set[j];
}

if (sum == val) {

count++;
}
}
if (count == 0) {
cout << ("No subset is found") << endl;
}
else {
cout << count << endl;

int main()
{
int t,n,sum;
cin>>t;
while(t--)
{
cin>>n;
int set[n];
for(int i=0;i<n;i++)
cin>>set[i];
cin>>sum;
printSubsetsCount(set, n, sum);
}

JAVA
import java.io.*;
import java.util.*;
class Main {

static void printBool(int n, int len)


{

while (n>0) {
if ((n & 1) == 1)
System.out.print(1);
else
System.out.print(0);

n >>= 1;
len--;
}

while (len>0) {
System.out.print(0);
len--;
}
System.out.println();
}

static void printSubsetsCount(int set[], int n, int val)


{
int sum;
int count = 0;
for (int i = 0; i < (1 << n); i++) {
sum = 0;
for (int j = 0; j < n; j++)

if ((i & (1 << j)) > 0) {


sum += set[j];
}

if (sum == val) {

count++;
}
}

if (count == 0) {
System.out.println("No subset is found");
}
else {
System.out.println(count);
}
}

public static void main(String[] args)


{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int n,sum;
while(t>0)
{
n=sc.nextInt();
int set[] = new int[n];
for(int i=0;i<n;i++)
set[i] = sc.nextInt();
sum = sc.nextInt();
printSubsetsCount(set, n, sum);
t--;
}

}
}

PYTHON
def printBool(n, len):
while n:
if n & 1:
print("1 ")
else:
print("0 ")
n = n >> 1
len -= 1

while len:
print("0 ")
len -= 1
print()

def printSubsetsCount(set, n, val):


sum = 0
count = 0
for i in range(0, 1 << n):
sum = 0

for j in range(0, n):

if (i & 1 << j) > 0:


sum += set[j]

if (sum == val):

count += 1

if (count == 0):

print("No subset is found")

else:
print(count)

t=int(input())
set = []
while t>0:
n = int(input())
set = list((map(int,input().strip().split())))[:n]
Sum = int(input())
printSubsetsCount(set, n, Sum)
t = t-1

Q3) Before the outbreak of corona virus to the world, a meeting happened in a room in Wuhan. A
person who attended that meeting had COVID-19 and no one in the room knew about it! So
everyone started shaking hands with everyone else in the room as a gesture of respect and after
meeting unfortunately every one got infected! Given the fact that any two persons shake hand
exactly once, Can you tell the total count of handshakes happened in that meeting?
Input Format :
The first line contains the number of test cases T, T lines follow.
Each line then contains an integer N, the total number of people attended that meeting.
Output Format :
Print the number of handshakes for each test-case in a new line.
Constraints :
1 <= T <= 1000
0 < N < 106
Sample Input :
2
1
2
Output :
0
1
Explanation :
Case 1 : The lonely board member shakes no hands, hence 0.
Case 2 : There are 2 board members, 1 handshake takes place.

Solutions:
C Language
#include <stdio.h>

int main()
{
int t,n; scanf("%d",&t);
long int sum = 0;
while(t--){
scanf("%d",&n);
n--;
sum = (n*(n+1))/2;
printf("%ld\n",sum);
}
return 0;
}

C++
#include <iostream>
using namespace std;

int main()
{
int t,n,sum; cin >> t;
long long sum;
while(t--){
cin >> n;
n--;
sum = (n*(n+1))/2;
cout << sum << endl ;
}
return 0;
}

JAVA
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t,n;
long sum;
t = sc.nextInt();
while(t > 0){
n = sc.nextInt();
n--;
sum = (n*(n+1))/2;
System.out.println(sum);
t--;
}
}
}

PYTHON
t = int(input())
while t > 0 :
n = int(input())
n = n-1;
print((n*(n+1))//2)
t = t-1

Q4) For enhancing the book reading, the school distributed story books to students as part of the
Children’s Day celebrations. To increase the reading habit, the class teacher decided to exchange
the books every week so that everyone will have a different book to read. She wants to know how
many possible exchanges are possible.
If they have 4 books and students, the possible exchanges are 9. Bi is the book of i-th student and
after the exchange, he should get a different book, other than Bi.
B1 B2 B3 B4 – first state, before exchange of the books
B2 B1 B4 B3
B2 B3 B4 B1
B2 B4 B1 B3
B3 B1 B4 B2
B3 B4 B1 B2
B3 B4 B2 B1
B4 B1 B2 B3
B4 B3 B1 B2
B4 B3 B2 B1
Find the number of possible exchanges, if the books are exchanged so that every student will receive
a different book.
Constraints
1<= N <= 1000000
Input Format
Input contains one line with N, indicates the number of books and number of students.
Output Format
Output the answer modulo 100000007.
Refer the sample output for formatting
Sample Input :
4
Sample Output :
9

Solutions:
C Language
#include <stdio.h>

int main()
{
int mod = (int)1e7+7;
long int n,a=0,b=1,c=2,d,i;
scanf("%ld",&n);
if(n==1 || n==2)
printf("%ld",n-1);
else{
for(i=3 ; i<=n ; i++){
d = (c * (a + b)) % mod ;
a = b;
b = d;
c++;
}
printf("%ld",d);
}
return 0;
}

C++
#include <iostream>
using namespace std;
int main()
{
int mod = (int)1e7+7;
long int n,a=0,b=1,c=2,d,i;
cin >> n;
if(n==1 || n==2)
cout << (n-1);
else{
for(i=3 ; i<=n ; i++){
d = (c * (a + b)) % mod ;
a = b;
b = d;
c++;
}
cout << d;
}
return 0;
}

JAVA
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int mod = (int)1e8+7;
long n,a=0,b=1,c=2,d=0;
n = sc.nextLong();
if(n==1 || n==2)
System.out.println(n-1);
else{
for(int i=3 ; i<=n ; i++){
d = (c * (a + b)) % mod ;
a = b;
b = d;
c++;
}
System.out.println(d);
}
}
}

PYTHON
mod = 100000007;
a=0
b=1
c=2
d=0
n = int(input())
if n==1 or n==2:
print(n-1)
else :
for i in range(1,n) :
d = (c * (a + b)) % mod
a=b
b=d
c=c+1
print(d)
Q5) You are given a string A and you have to find the number of different sub-strings of the string A
which are fake palindromes.

Note:

1. Palindrome: A string is called a palindrome if you reverse the string yet the order of letters
remains the same. For example, MADAM.

2. Fake Palindrome: A string is called as a fake palindrome if any of its permutations is a


palindrome. For example, AAC is fake palindrome, but ACD is not.

3. Sub-string: A sub-string is a contiguous sequence (non-empty) of characters within a string.

4. Two sub-strings are considered same if their starting indices and ending indices are equal.

Input Format:

First line contains a string S

Output Format:

Print a single integer (number of fake palindrome sub-strings).

Constraints:

1 <= |S| <= 2 * 105

The string will contain only Upper case 'A' to 'Z'

Sample Input 1:

ABAB

Sample Output 1:

Explanation:

The fake palindrome for the string ABAB are A, B, A, B, ABA, BAB, ABAB.

Sample Input 2:

AAA

Sample output 2:

Explanation:
The fake palindrome for the string AAA are A, A, A, AA, AA, AAA
Solutions:
C++
#include <bits/stdc++.h>
using namespace std;

void countSubstring(string s)
{
int res = 0;

for (int i = 0;
i < s.length(); i++) {

int x = 0;

for (int j = i;
j < s.length(); j++) {

int temp = 1 << s[j] - 'a';

x ^= temp;
if ((x & (x - 1)) == 0)
res++;
}
}
cout << res;
}
int main()
{
string str;
getline(cin,str);
countSubstring(str);
return 0;
}

JAVA
import java.util.*;
class Main{
static void countSubString(String s)
{
int res = 0;
for (int i = 0; i < s.length(); i++)
{
int x = 0;
for (int j = i; j < s.length(); j++)
{
int temp = 1 << s.charAt(j) - 'a';
x ^= temp;
if ((x & (x - 1)) == 0)
res++;
}

}
System.out.print(res);

}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
countSubString(str);

PYTHON
def countSubString(s):

res = 0;

for i in range(len(s)):
x = 0;
for j in range(i, len(s)):

temp = 1 << ord(s[j]) - ord('a');

x ^= temp;
if ((x & (x - 1)) == 0):
res += 1;

print(res);

if __name__ == '__main__':
str = input();

countSubString(str);

You might also like