preface

During the interview, it is inevitable that students will encounter baffling logic questions. This kind of questions often make students not even know what the answer should be, and they can only make eye contact with the interviewer, which is very awkward.

In fact, many interview examiners, are randomly selected from the question bank logic questions to test the students, sometimes the interviewer may not fully understand this kind of topic, so the interview do not have to be too nervous, even if you can not answer ah is very normal.

In my understanding, this kind of topic basically still tests everybody’s train of thought, as to answer standard or not, is not particularly important actually.

This article summarizes the interview in my own interview encountered several very common logic questions, we can be used as the interview before the surprise review material.

Interview knowledge review manual

This article is part of the Java backend review Manual column

Full review manual article navigation: View through the following two ways

  • Follow my public id: Rude3Knife Below the navigation bar: Java Interview Review Manual
  • Full Review Manual Article Navigation (CSDN)

—– Start —–

Red and white hat reasoning

By: Rude3Knife

Topic describes

A group of people were having a ball, and everyone was wearing a hat. There are only black and white hats, and at least one of them is black. Everyone can see the color of other people’s hats, but not their own. The host first showed everyone what hats others were wearing, then turned off the lights and slapped anyone who thought they were wearing a black hat. The first time I turned off the lights, there was no sound. So the light was turned on again, and everyone looked at it again. It wasn’t until the third time the light was turned off that there was a slap. How many people are wearing black hats?

The answer

Three people

If there are two people, let A and B be black hats, the second time to turn off the light will be slapped. The reason is that when A sees that B didn’t slap him the first time, he knows that B must have seen A man with A black hat, too. But A knows that B is wearing A black hat, and everyone else is wearing A white hat. Similarly, B thinks the same way, so the second time the lights go out, there will be two slaps.

If it’s three people, A,B,C. The first time A didn’t slap, because he saw B and C were wearing black hats; And let’s say I’m wearing a white hat, so only BC is wearing a black hat; By the inference that only two men wore black hats, someone should have slapped the second time; But not the second time… Then he knew that B and C must have seen someone else wearing a black hat besides BC, so he knew that BC must have seen him, so the third time three of them slapped themselves

expand

If N people are black hats, on day NTH, N people slap themselves.

Eat pills

18 Autumn Recruit NetEase test development of one original topic (by: Rude3Knife)

Topic describes

One is two pills, two of each kind, and one person needs to take one of each of the two pills in the morning, and now these four pills are mixed together and how does this person take them?

The answer

Cut all four pills into equal halves and eat half of each pill in the morning and half in the evening

You get a specified amount of water

18 Autumn Recruit NetEase test development of one original topic (by: Rude3Knife)

Topic describes

A 5L bottle, a 6L bottle, to get 3L of water, ask what method

The answer

6-5=1 1L of water in the 5L bottle, and then fill 6L of water into the 5L (there is already 1L of water in it), so that there will be 2L of water left in the 6L, and then put 2L of water in the 5L, and then fill it again, and then you can fill the 6L with 3L of water everywhere in the 5L, and then you will have 3L of water left

Rats/prisoners drink alcohol to test the poison

Topic describes

There were 1000 bottles of wine, one of which was poisonous. If a mouse drank poisoned wine and died a day later, how many mice would it take to determine which bottle of wine was poisoned if given a day?

The answer

The answer is 10. This is done in binary code, and 1000 bottles of wine require at least 10 binary digits to encode. And then you take ten cups, one for each of the ten bits of this binary number, and you pour 1000 bottles of wine into each of those cups with the number 1. Ten mice were taken to drink wine from ten cups, and a day later, the code of the poisoned wine could be determined based on the death of the mice who drank the wine, thus determining which wine was poisonous. The basis is that only the poisoned wine code corresponds to the location of the poisoned mouse’s cup. This topic takes advantage of some of the features of binary coding.

expand

There are other problems that use these features, such as using special bit operations, usually with, or and xOR. In this way, it can correspond to some problems in real life. For example, a similar problem originally needs more than 900 servers to solve, but after such analysis, we can use 10 servers to solve it, greatly saving the cost.

Another example is that the king has 10,000 barrels of wine, one of which is known to be poisonous and will die within 23-24 hours after drinking (for example, if drunk at 0 o ‘clock, death will occur between 23 and 0 o ‘clock the next day). Now the King is hosting a banquet in 48 hours, and we need to experiment with criminals. How many criminals are the minimum? (Can be mixed)

If we were to solve the problem using binary, we would need 14 prisoners, 2^14= 16,384 > 10,000, but then we wouldn’t need time of death, and it wouldn’t be optimal.

Should take advantage of the alcohol death time is fixed, one criminal can represent 25 states as above, three criminals can represent 25 x25 x25 states, more than 10,000, so only three criminals are needed.

Ball weighing

Topic describes

There are eight balls, seven of which are the same weight and one is lighter. Give you a scale and ask the scale how many times you can find the lighter ball. If the scale can only be weighed twice, how should it be weighed

The answer

The first time each side put a random three, if flat, the other one is light, if uneven, and the second time, take out the three light, put a random on both sides, you can measure which is the lightest.

refueling

18 autumn recruit Tencent test development side of the original topic (by: pretty three knives knife)

Body diagram reference:

Blog.csdn.net/hinyunsin/a…

Topic describes

Known: each plane has only one tank, planes can refuel each other (note: mutual, there is no separate tanker), a tank of fuel enough for a plane to fly half a circle of the earth

Question: How many planes would it take to get at least one plane to circle the earth once and return to the airport from which it took off? (All planes take off from the same airport and must return to the airport safely. No landing is allowed. There is no airport in between.)

The answer

It was divided into 5 sorties by 3 aircraft and 6 sorties by 3 aircraft

1. 6 sorties, flown by 3 aircraft

(Above) Three ABCs take off at the same time

(Above) at 1/8, C refuels AB and C returns. At this time, the oil volume of the aircraft is: A: 3/4, B: 3/4, C: 3/4. At this point, C fills up the oil for A and B respectively, and the current oil levels of the three planes are: A: 1, B: 1 and C: 1/4 respectively. C Return to the airport. A and B continue to fly forward.

(Figure above) At 1/4, B fills up the fuel for A, B returns to flight, A arrives at 1/2, and C has returned to the airport. At this time, the oil amount of the three planes is: A: 3/4, B: 3/4, C: 0. At this point, B fills up the oil for A and C, and the oil amount of the three planes is: A: 1, B: 1/2 and C: 1 respectively. B then returns to the airport and A continues on.

(Figure above) When A flies to the half-circle position, B has returned to the airport and filled up the fuel (assuming the refueling time is 0). At this time, B and C fly counterclockwise, and the current fuel amount of the three planes is: A: 1/2, B: 1 and C: 1 respectively. A Continue flying ahead.

(Figure above) When A flies to 1/4 of the other half of the circle, the remaining oil amount of the three planes is: A: 1/4, B: 3/4 and C: 3/4. At this point, C fills up the tank for B. At this time, the oil amount of the three aircraft is: A: 1/4, B: 1, C: 1/2. C returns to the airport, and B and A continue their flight.

When A flies to the 1/2 position of the other half circle, C has returned to the airport and A and B meet. At this time, the remaining oil amount of the three planes is: A: 0, B: 3/4 and C: 0. B adds 1/4 oil to A, and the remaining amount of oil for the three aircraft is: A: 1/4, B: 1/2, C: 1. C fills up and flies counterclockwise from the airport, B returns to the airport, and A continues to fly forward.

A and C meet as A flies to 3/4 of the other half of the circle. At this time, the oil amount of the three planes is: A: 0, B: 1/4, C: 3/4. C adds 1/4 oil to A. At this time, the oil amount of the three planes is: A: 1/4, B: 1/4, C: 1/2. C turns around and returns to the airport, while A and B continue flying forward.

All three planes made it back to the airport!

2.3 Aircraft, 5 sorties

(1) Three aircraft depart from the airport at the same time, covering one eighth of the journey (point A), each consuming one fourth of the fuel. One aircraft refuels the other two and returns to base.

(2) Another aircraft accompanies the target aircraft, flies to a quarter of a week (point B), refuels the target aircraft and returns on its own;

(3) Target aircraft flies alone for half a week (point C);

(4) Meet an aircraft departing from the base in the opposite direction, and the two aircraft will split the oil equally and fly to the last eighth of the point (D);

(5) Meet the other aircraft starting from the reverse side of the base, each with a quarter of the oil, and return.

Develop reading

75 programmer interview logic questions and answers

Blog.csdn.net/qq_38361726…

—– End —–

Full review manual article navigation: View through the following two ways

  • Follow my public id: Rude3Knife Below the navigation bar: Java Interview Review Manual
  • Full Review Manual Article Navigation (CSDN)

Review manual articles are recommended

  • Java Basics Interview Manual
  • Java container (List, Set, Map) quick review manual
  • Java Concurrent Knowledge quick review manual (part 1)
  • Java Concurrent Knowledge quick review manual (ii)
  • Java Virtual Machine Knowledge quick review manual (part 1)
  • Java Virtual Machine Quick Review manual (part 2)
  • Quick review of 23 commonly used design patterns
  • Redis Basic Knowledge interview manual
  • Summary of small algorithms often asked in interviews
  • Search algorithm summary and some algorithms implemented in Python/Java
  • Sorting algorithm and its implementation (Python/Java)
  • HTTP should know should know knowledge review manual (1)
  • HTTP should know should know knowledge review manual (ii)
  • Computer network basic knowledge point quick review manual
  • Massive data processing problems knowledge points review manual
  • . Etc. (please see the full review manual navigation)

Pay attention to my

I am currently working as a back-end development engineer. Focus on back-end development, data security, web crawler, Internet of Things, edge computing and other directions.

WeChat: yangzd1102

Making: @ qqxx6661

Personal Blog:

  • CSDN: @ Rude3Knife
  • Zhihu: @ Zhendong
  • Jane: @pretty three knives a knife
  • Nuggets: @ pretty three knife knife

Original blog main content

  • Java knowledge points review the full manual
  • Leetcode algorithm parsing
  • Sword point offer algorithm analysis
  • SpringCloud rookie combat series
  • SpringBoot rookie combat series
  • Technical articles about Python crawlers
  • Technical articles related to back-end development

Personal public account: Rude3Knife

If this article is helpful to you, save it and send it to your friends