Problem : A certain town comprises of 100 married couples. Everyone in the town lives by the following rule: If a husband cheats on his wife, the husband is executed as soon as his wife finds out about him. All the women in the town only gossip about the husbands of other women. No woman ever tells another woman if her husband is cheating on her. So every woman in the town knows about all the cheating husbands in the town except her own.
[Read More]
50 trucks with payload
Problem : Given a fleet of 50 trucks, each with a full fuel tank and a range of 100 miles, how far can you deliver a payload? You can transfer the payload from truck to truck, and you can transfer fuel from truck to truck. Assume all the payload will fit in one truck.
Solution : We want to use as little fuel as possible so we try minimize the number of trucks we use as we go along.
[Read More]
Camel and Banana
Problem : The owner of a banana plantation has a camel. He wants to transport his 3000 bananas to the market, which is located after the desert. The distance between his banana plantation and the market is about 1000 kilometer. So he decided to take his camel to carry the bananas. The camel can carry at the maximum of 1000 bananas at a time, and it eats one banana for every kilometer it travels.
[Read More]
Red, Green and Yellow Balls - heavy and light
Problem : You are give two red balls, two green balls and two yellow balls. One ball from each color is heavier than the other one. All the heavier balls weigh the same and all the lighter balls weigh the same. You are only provided with a weighing balance. How many tries would it take to identify which one is heavier and which one is lighter?
Solution : Let’s label the balls R1, R2 (Red ones), G1, G2 (Green ones) and Y1, Y2 (Yellow ones).
[Read More]
int atoi( char* pStr )
Problem: Write the definition for this function without using any built-in functions. if pStr is null, return 0. if pStr contains non-numeric characters, either return 0 (ok) or return the number derived so far (better) (e.g. if its “123A”, then return 123). assume all numbers are positive. plus or minus signs can be considered non-numeric characters. in order to solve this program, the programmer must understand the difference between the integer 0 and the character ‘0’, and how converting ‘0’ to an int, will not result in 0.
[Read More]
Reverse a String
Problem: A typical programming interview question is “reverse a string, in place”. if you understand pointers, the solution is simple. even if you don’t, it can be accomplished using array indices. i usually ask candidates this question first, so they get the algorithm in their head. then i play dirty by asking them to reverse the string word by word, in place. for example if our string is “the house is blue”, the return value would be “blue is house the”.
[Read More]
The Circular Lake Monster Problem
Problem: For #1, how about row in a circle a bit smaller 1/4r in size. Since he won’t be able to keep up with you, when he is on the opposite shore you can make a brake for it. You have r*3/4 to travel, but 4*3/4 is less then pi, so he won’t be able to catch you in time
Solution: Assume x is the monster’s speed. Then to get the circle trick to work, you row a circle a little less than 1/x of the radius, leaving you 1 - 1/x to row when he is opposite of you.
[Read More]
Array of 0 and 1, put 0's at even position and 1's at odd position
you are given an array of integers containing only 0s and 1s. you have to place all the 0s in even position and 1s in odd position and if suppose no if 0s exceed no. of 1s or vice verse then keep them untouched. Do that in ONE PASS and WITHOUT taking EXTRA MEMORY.
input array:
{0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 1 1 }
[Read More]
Chain Cut Problem
Problem: What is the least number of links you can cut in a chain of 21 links to be able to give someone all possible number of links up to 21
Solution: Assume that a chain of length k for every 1<=k<=length(chain) must be doable with the open links. Then you can reach **links length dissection** 0 1 1 1 5 1-(1)-3 2 13 1-(1)-3-(1)-7 3 29 1-(1)-3-(1)-7-(1)-15 4 61 1-(1)-3-(1)-7-(1)-15-(1)-31 n 2^(n+2)-3 we have taken links as 2^k-1.
[Read More]
CTS Aptitude Question paper(Yellow)
Question 1:
If all the 6 are replaced by 9, then the algebraic sum of all the numbers from 1 to 100(both inclusive) varies by
Answer: 330
Question 2:
The total no. of numbers that are divisible by 2 or 3 between 100 and 200(both inclusive) are?
Answer: 67
Question 3:
From a pack of cards Jack, Queen, King & ace are removed. Then the algebraic sum of rest of the cards is?
[Read More]