Skip to main content

Posts

Showing posts with the label Puzzle

Puzzle - How long does it take for the dogs to catch each other and where?

Question:                   There are four dogs each at the corner of a unit square. Each of the dogs starts chasing the dog in the clockwise direction. They all run at the same speed and continuously change their direction accordingly so that they are always heading straight towards the other dog. How long does it take for the dogs to catch each other and where? Answer & Explanation :                   Let the dogs be A, B, C and D where A is chasing B, B is chasing C, C is chasing D and D is chasing A. All the dogs will eventually meet in the center of the square. Since all the dogs move in symmetry, the only logical answer to the location of their meeting is the center of the square. At any point in time, dog A is perpendicular to dog B and B perpendicular to C and so on. Dog A moves towards dog B...

Challenge – Equal Probability between 1 and 7

Question:               Write a method to generate a random number between 1 and 7, given a method that generates a random number between 1 and 5. The distribution between each of the numbers must be uniform. Answer:               Let’s think of this like a decision tree. Each rand5() will be a decision. After 2 tries, we have 25 possible solutions. We try to get maximum bunches of 7 as we can (1 – 21, 3 sets of 7). If we get any of the other values, we just try again. Since the probability of getting each of 21 values are the same every time, trying again won’t affect their probabilities.       int rand7() { while (1) { int num = 5*(rand5()-1) + rand5(); if (num < 22) return ((num % 7) + 1); } } That was fun, right? Anyone up for another challenge? Watch out for it next tuesday (March 1st)...

Challenge – Find First Common Ancestor

Question:                How would you find the first common ancestor of two nodes in a binary search tree? First as in the lowest in the tree. Another way to ask is to find the lowest common ancestor of two nodes.  Meanwhile, check out the challenges from previous weeks here Answer: TreeNode findFirstCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if (root == null) { return null; } if (root == p || root == q) { return root; } TreeNode left = findFirstCommonAncestor(root.left, p, q); TreeNode right = findFirstCommonAncestor(root.right, p, q); if ((left == p && right == q) || (left == q && right == q)) { return root; } return (left != null) ? left : right; } Alternate: TreeNode findFirstCommonAncestor(TreeNode root, int p, int q) { if (root == null) { return null; } if (root.value == p || root.va...

Challenge – 50 trucks with payload

Question:                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.  Meanwhile, check out the challenges from previous weeks here Answer :               We want to use as little fuel as possible so we try minimize the number of trucks we use as we go along. Let’s say we start with all 50 trucks with full fuel (5000 miles range). For each mile, we lose 50 miles in range. After two miles, we lose 100 miles leaving us with 4900 miles. This can be supported by 49 trucks so we drop one truck. As you can see for every 100 miles we lose in range, we drop a truck. 50 trucks: 100/50 49 trucks: 100/49 … Total distance = 100/50 + 100/49 + 100/48 + … + 1...

Challenge – Camel and Bananas Comment your Answer

Question: 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. What is the largest number of bananas that can be delivered to the market? Challenge: Do you know the answer to this question? Post in the comments. The Answer will be posted on 10th Sept   You Can see the Answer for this Challenge Here After Scheduled Date

Puzzle and Interview Questions 2 - 08 sep 2012

Question:  Count the number of Cubes     Press Button to See the Answer See Answer

Some (Unknown) Facts and the Important Questions and answers

Q.  How much is the playing time of Indian National Anthem? A.  Approx 52 seconds Q.  What is the name of the first month of National Calendar of India? A.  Chaitra Q.  What kind of forests cover maximum area in India? A.  Tropical Dry Deciduous Forests Q.  What is the stretch of India from north to south? A.  3200 Kms Q.  Which Veda gives the first classification of PRAN ( Respiration)? A.  Rig Veda Q.  What was the name of State Bank of India Before Nationalization? A.  Imperial Bank of India Q.  Which Kind of Forests occupy the highest percentage in India Area Wise? A.  Tropical Deciduous Q.  The only paramilitary force which has an exclusive ‘Mahila Battalion’ is A.  CRPF batch – 88 Q.  The largest paramilitary force in India A.  Central Reserve Police Force (CRPF) Q.  Who wrote the book Tehqiq-i-Hind? A.  Alberuni. Q.  What was the biggest building at Mohen...

Puzzle and Interview Questions 1 - 11 Aug 2012

Question: A contractor had employed 100 labourers for a flyover construction task. He did not allow any woman to work without her husband. Also, atleast half the men working came with their wives. He paid five rupees per day to each man, four ruppes to each woman and one rupee to each child. He gave out 200 rupees every evening. How many men, women and children were working with the constructor? Answer: Press Button To See Answer Display Answer