[Post] share interesting interview questions

Source: Internet
Author: User

Address: http://www.matrix67.com/blog/archives/501

Http://www.matrix67.com/blog/archives/502

 

 

I accidentally entered this page and saw several questions about the interview I have never seen before. Shunba also translated some rare questions that may have never been seen before and written them here. There are several questions that have been widely circulated in China. How can n people divide the pie into the most equitable ones? Which switch controls the three bulbs in the house and three planes travel around the world, using matches and two ropes to measure questions such as 45 minutes, Mars has to be archaeological, and I will not talk about it here. I have provided a detailed introduction to some topics in this blog, and I will not mention them here.

1. consider a two-person game. The game is played on a round table. Each player has enough coins. They need to take turns to place coins on the table, each time they need and can only place one coin, requiring the coins to be placed completely inside the desktop (not part of them hanging outside the table ), and it cannot overlap with the unused coins. Whoever has no place to place new coins will lose. Do game pioneers or practitioners have a winning strategy? What is this policy?
Answer: The Pioneer places a coin in the center of the table, and the coins in the future are always placed in a position relative to the place where the Walker just put it. In this way, as long as the practitioners can put it, the pioneers must also put it somewhere. The pioneers will win.

2. append space with linear time and constants to reverse the words (not characters) in an article.
Answer: first, sort all the characters in the entire article in reverse order (starting from the two ends and constantly exchanging characters with relative names). Then, use the same method to sort the characters in each word in reverse order. In this way, the word order in the entire article is reversed, but the word itself is reversed.

3. Use the space appended with linear time and constant to move a string of N to the Left Loop (for example, "abcdefg" moves 3 bits to "defgabc ").
Answer: cut the string into two halves: M and N-M. Sort the two parts in reverse order, and then sort the entire string in reverse order.

4. A rectangular cake with a hollow rectangle inside it. With only one knife, how can I cut the cake into two equal parts?
Answer: I noticed that the line of the area of the split rectangle goes through the center of the rectangle. The center of the large rectangle and the hollow rectangle draw a line. This line clearly divides the two rectangles into half, and their difference is of course equal.

5. a rectangle of chocolate, initially composed of N x m small pieces. Each time you break a piece of chocolate into two small rectangles. How many times does it take to split them into N x m pieces of 1 X1 small chocolate?
Answer: N x m-1 is enough. This number is also required, because after each split, the current number of chocolate segments can only be increased by one, divide the chocolate into N x M Blocks, of course, at least need to split N x m-1 times.

6. How to quickly find out the number of "1" in the Binary Expression of a 32-bit integer "? What is the linear time used for the number of "1?
Answer 1 (linear number of digits): For (n = 0; B; B >>= 1) if (B & 1) n ++;
Answer 2 (linear number of "1"): For (n = 0; B; n + +) B & = B-1;

7. An array of n size, all numbers are positive integers not greater than the N-1. Use the O (n) Time to find the number of duplicates (assuming there is only one ). An array of N in size. All numbers are positive integers not greater than N + 1. Use the O (n) Time to find the number that has not appeared (assuming there is only one ).
Answer: Calculate the sum of all the numbers in the array, and then calculate the sum of all the numbers from 1 to the N-1, the difference between the two is the repeated number. Calculate the sum of all numbers in the array, and then calculate the sum of all numbers from 1 to n + 1. The difference between the two is the missing number.

8. a c expression is provided to determine whether the given integer is a power of 2.
Answer: (B & (b-1) = 0

9. How many points on the Earth have taken a mile from this point to the south, a mile to the east, and then a mile to the north to return to the starting point?
Answer: "North Point" is a traditional answer. In fact, there are other answers to this question. In fact, there are infinite vertices that meet the requirements. All the places that are 1 + 1/(2 π) miles from the South Pole meet the requirements, and walk one mile south to reach 1/(2 π) from the South Pole, take a mile to the east and then round the latitude circle for a week. Then, go north to the original path and return to the starting point. In fact, this is still not all the points that meet the requirements. The distance from the South Pole 1 + 1/(2 k π) is acceptable, where K can be any positive integer.

10. A and B are on the two islands respectively. B is ill. A has the medicine required by B. C has a boat and a lockable box. C is willing to transport east and west between A and B, but things can only be placed in boxes. C will steal everything in the box as long as the box is not locked. If a and B each have a lock and can only open their own key to the lock, how should a safely deliver things to B?
Answer: A puts the medicine in the box and uses his lock to lock the box. B. After obtaining the box, add a lock to the box. After the box is moved back to a, a removes its own lock. When the box is moved to B's hand, B removes his lock and obtains the medicine.

11. A couple invited a N-1 couple to the party (so there was a total of 2n members at the party ). Everyone holds hands with people they don't know. Then, the male master asked all the other people (2n-1 people in total) to hold their hands several times and all the answers were different. If everyone knows their spouse, How many times does the hostess hold the hand?
Answer: The number of handshakes can only be the 2n-1 number from 0 to 2N-2. Except for the male Master, there are a total of 2n-1 individuals, so each number exactly appears once. One of them (0) did not shake hands, and another (2N-2) shook hands with all other couples. The two must be a couple; otherwise, the latter will shake hands with the former (so that the number of handshakes of the former is no longer 0 ). Aside from the couple, one (1) held only with (2N-2), one (2n-3) and the other (0) both held hands. The two must be a couple; otherwise, the latter will shake hands with the former (so that the number of handshakes of the former is no longer 1 ). And so on, until the person holding the N-2 and the person holding the n hands are paired with one. At this time, all except the male master and its spouse have been paired. According to the Division, the last handshake for the N-1 is the hostess.

 

12. The two robots are initially located at different locations on the number axis. Enter the two robots into the same program so that they can meet each other. The program can only contain "shift n units left" and "shift n units right". If is a conditional judgment statement, while is a repeating statement, and two functions that return the Boolean value "at their own start point" and "at the other's start point ". You cannot use other variables or counters.
Answer: The two robots start to shift right at the same time per unit until one robot moves to the start point of another robot. The robot then catches up with each other at double speed. The program is as follows.

While (! At_other_robots_start ){
Move_right 1
}
While (true ){
Move_right 2
}

13. Which of the following two types of games do you choose? Why?
A. Write down a sentence. If this sentence is true, you will get 10 US dollars; if this sentence is false, you will get less than 10 US dollars or more than 10 US dollars (but not exactly 10 US dollars ).
B. Write down a sentence. No matter whether the sentence is true or false, you will get more than 10 dollars.
Answer: select the first game and write "I don't get $10 or $10000000 ".

14. You are under a 100-storey building, with 21 wire headers marked with numbers 1 .. 21. These wires extend to the roof of the building, and the head of the roof is marked with a .. u. You do not know the correspondence between the following numbers and the above letters. You have a battery, a light bulb, and many very short wires. How can we determine the ing between the wire and cable headers only once?
Answer: connect 2 and 3, Connect 4 to 6, and connect 7 to 10, in this way, you divide the wires into six "equivalence classes" in the sizes of 1, 2, 3, 4, 5, and 6. Then, go to the roof to determine which wires are not connected to all other wires, which are connected to the other wires, and which are connected to the other two wires, to determine the letter .. which of the following equivalence classes does U belong. Now, connect the first letter in each equivalence class to form a new equivalence class of 6, and then connect the second letter in the last five equivalence classes, form a new equivalence class of 5, and so on. Go back to the downstairs and differentiate the new equivalence classes. In this way, you will know the first letter of the original equivalence class corresponding to each number to solve the problem.

15. A prescription is very strict. You must take one tablet a and one tablet B each day. This kind of medicine is very expensive and you don't want to waste anything. One day, you open the medicine bottle containing tablet a, pour out a tablet and put it in your hand; then open another medicine bottle, but accidentally pour out two pills. Now you have a tablet a and two tablet B in your hand, and you cannot tell which is a and which is B. How can you strictly follow the prescription to take pills without any waste?
Answer: Cut the three pieces of medicine on your hands into two halves and divide them into two heaps. Take a tablet a and cut it into two halves. Then add the first half of a to each heap. Now, each heap of pills exactly contains two half-slices of A and two half-slices of B. Take a bunch of them a day.

16. You are on a ship. The computer on the ship has n processors. Suddenly, the spacecraft was attacked by an alien laser weapon, and some processors were damaged. You know that more than half of the processors are still good. You can ask one processor whether the other processor is good or bad. A good processor always tells the truth, and a bad processor always tells lies. Find a good processor with a N-2 inquiry.
Answer: Give the processor A number ranging from 1 to n. Use the symbol A-> B to ask whether processor B is good to the processor labeled as. First, ask 1-> 2. If 1 says no, remove both of them (if a good and a bad one are removed, then the remaining processor is better than half ), then start from 3-> 4. If 1 says 2 is okay, continue to ask 2-> 3, 3-> 4 ,...... Until one time J says J + 1 is bad, remove J and J + 1, then ask J-1-> J + 2; or ask questions starting with J + 2-> J + 3 if there is no J-1 before (it has been removed before ). Note that you have always maintained such a "chain", and each of the previous processors said that the latter is good. All the processors in this chain are either good or bad. As this chain grows and the remaining processors become fewer and fewer, the chain is always more than half of the remaining processors. At this time, we can be sure that all the processors in this chain are good. Or, if more and more processors are removed and the chain length is still 0, and only one or two processors are left blank, they must be okay. I also noted that the quality of the first processor has never been asked. Think carefully and you will find that the quality of the last processor cannot be asked (once the chain length exceeds half of the remaining processor, or the last not removed is only this one, you don't ask), so the number of inquiries will not exceed the N-2.

17. A disc is coated with black and white colors, each of which occupies a half circle. The disc rotates at an unknown speed in an unknown direction. You have a special camera that allows you to instantly observe the color of a dot on the circle. How many cameras do you need to determine the direction of the disc rotation?
Answer: You can place two cameras on two similar points on the disc, and then observe which point changes first. In fact, only one camera is enough. It controls the clockwise movement of the camera around the center of the disc to observe how often the color changes. Then, let the camera move around the center of the disc at the same speed and observe the color changing frequency again. It can be determined that the rotation direction of the camera is the same as that of the disc when the color change frequency is slow.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.