当前位置:网站首页>Interview intelligence questions
Interview intelligence questions
2022-06-12 06:55:00 【ToLoveToFeel】
Interview intelligence questions
1. Weight weighing problem
problem 1
- There are ten sets of weights , Ten in each group , The weight of each weight of nine groups is 10g, The weight of each weight in the other group is 9g, Ask for a scale that can show grams , Find this group at least a few times 9g The weight of ?
analysis
- Divide the weight into
1~10Group , The first group takes out1A weight , The second group takes out2A weight , The third group takes out3A weight ,…, The last group takes out10A weight , Put it all on the scale , The weight shown isy, Makex=550-y, Is the firstxGroup is the weight of the weightxA group of .
problem 2
- There's a scale ,9 A weight , Among them is 1 One is better than the other 8 A light , Ask if you can find the light weight at least several times ?
analysis
Divide the weight into 3 Group , Each group 3 individual , Take two of them and weigh them on the balance ( The first 1 Time ), If it's the same weight , The light one is the remaining group , Not as heavy , You can also tell which group is light ;
The lighter group 3 A weight , Choose two of them and weigh them on the balance ( The first 2 Time ), If it's the same weight , Then the rest 1 One is light , Not as heavy , The light ones can also be easily found .
2. The kettle problem
problem 1
- There is now an unlimited amount of water , You have two... Capacity 5L and 3L My jar , Please weigh out 4L water . Note that you can only fill or empty the jar at a time , Or pour water from one pot to another .
analysis
- We need to solve an indefinite equation :
5 × a + 3 × b = 4 5 \times a + 3 \times b = 4 5×a+3×b=4
Can take a = 2 , b = − 2 a = 2, b = -2 a=2,b=−2, It means that in the end
5LMy jar ( Write it down asA) Need to be filled twice ,4LMy jar ( Write it down asB) It needs to be poured out twice , The specific operation is as follows :take
AFill it up with , holdAPour the water inBin , And thenBPour out the water in , And thenAPour the remaining water inBin , here :A:0L、B:2L;take
AFill it up with , holdAPour the water inBin , And thenBPour out the water in , here :A:4L、B:0L;
problem 2
- There is now an unlimited amount of water , You have two... Capacity 5L and 6L My jar , Please weigh out 3L water .
analysis
- We need to solve an indefinite equation :
5 × a + 6 × b = 3 5 \times a + 6 \times b = 3 5×a+6×b=3
Can take a = 3 , b = − 2 a = 3, b = -2 a=3,b=−2, It means that in the end
5LMy jar ( Write it down asA) It needs to be filled three times ,4LMy jar ( Write it down asB) It needs to be poured out twice , The specific operation is as follows :take
AFill it up with , holdAPour the water inBin , here :A:0L、B:5L;take
AFill it up with , holdAPour the water inBin , here :A:4L、B:6L;hold
BPour out the water in , here :A:4L、B:0L;hold
APour the water inBin , here :A:0L、B:4L;take
AFill it up with , holdAPour the water inBin , here :A:3L、B:6L;hold
BPour out the water in , here :A:3L、B:0L;
Question 3
- There is now an unlimited amount of water , You have two... Capacity
xandyMy jar , Please weigh outzwater .
analysis
This problem is the most general problem of the above two problems . A necessary and sufficient condition for the existence of a scheme :
z<=x+yalsozaliquotgcd(x, y).For specific analysis, please refer to :【 Classic algorithm problem 】 The kettle problem .
3. Stone weight sorting problem
problem
- Give you a pile of stones with the same appearance , But the weight is different , You can also use a balance without weights , Ask how to arrange these stones in ascending order ?
analysis
The key of sorting algorithm is that it can compare the size of two numbers , It doesn't matter how much these two numbers are . Therefore, all sorts of sorting algorithms can be used .
You can use fast platoon : The idea is to find the location of each stone , You can put stones less than the current stone weight on the left , Put the larger ones to the right , Then solve recursively .
You can use merge sort : At first, it was thought that each stone was a pile , Then recursively merge two adjacent piles of stones .
You can use heap sort , Use
heapifyBuild a big pile , Then put the top of the heap element to the end each time , afterdown(1)that will do .
4. Burn the rope
problem 1
- It takes to burn a rope 1 Hours , How to use this rope to judge half an hour ?
analysis
- Start from both ends , When it's finished, it's half an hour .
problem 2
- It takes to burn a rope 1 Hours , How many ropes do you have , How to count an hour and 15 minutes with a burning rope ?
analysis
- Burn two ropes at the same time , One from one end , Burn one from both ends ; When the burning rope at both ends is finished ( Half an hour ), Ignite the other end of the burning rope ( It has been burning for half an hour ), When this rope burns out ( Fifteen minutes ); Light the third rope from both ends , When finished burning ( Half an hour ) One hour and fifteen minutes .
5. COINS
problem
- Yes 10 A coin with its face up ,10 A coin with the reverse side up , Mixed in with . You need to close your eyes , At the same time, you can't feel a coin face up , Or the opposite side up . You need to put this 20 Coins are divided into two piles , Make the number of coins facing up the same in the two stacks , The number of coins with the reverse facing upwards is the same .
analysis
It must be divided into two piles of the same number , All are 10 individual , Then turn one pile over .
Suppose there is... In a pile
xFace up , The other pile has10-xFace up , After turning, another pile hasxFace up , Meet the conditions .
6. A Poor Pig
problem 1
- Yes
1000Bucket water , Only one bucket of water is poisonous , You can feed water to the piglets , As long as the piglets drink poisonous water , You'll die . You can only feed one round ( Every barrel of water is treated once and counted as one round ). Ask how many piglets you need at least ? How to determine the toxic bucket of water ?
analysis
- The number of piglets needed :
⌈ l o g 2 ( 1000 ) ⌉ = 10 \lceil log_2(1000) \rceil = 10 ⌈log2(1000)⌉=10
Each barrel of water is numbered , Corresponding
0~999, You can convert numbers to binary , For a barrel of water , If a binary bit is 1, Feed this bucket of water to the corresponding piglet .Finally, determine which piglets are dead , Then the corresponding binary bit is 1, The binary bit corresponding to the undead pig is 0. In this way, the number of poisonous water can be determined .
problem
- The above questions remain basically unchanged , The only change is that you can feed
kround . Ask how many piglets you need at least ? How to determine the toxic bucket of water ?
analysis
- The number of piglets needed :
⌈ l o g k + 1 ( 1000 ) ⌉ \lceil log_{k+1}(1000) \rceil ⌈logk+1(1000)⌉
- Tips : Think of a barrel of water as a
k+1Hexadecimal number . For details, please refer to :【 Classic algorithm problem 】 A Poor Pig .
7. The hardness of the egg
- Definition : If the egg is in the
aThe first floor will not be broken , But in thea+1The first floor fell to pieces , The hardness of the egg isa( The egg hardness is less than or equal to the floor height ).
Question 1
- 100 floor , Do you have 1 An egg , To test the hardness of an egg , How many times do you need to throw ?
analysis
- Because there is only one egg , In order to ensure that the hardness of the egg is tested , You must test layer by layer from the first layer , So in the worst case it needs to be tested 100 Time ( The hardness of the corresponding egg is 100) The situation of .
Question two
- 100 floor , Do you have 2 An egg , To test the hardness of an egg , How many times do you need to throw ?
analysis
Refer to the website : Throwing eggs .
Two points : The first egg starts from 50 Throw it down on the first floor , Another egg can only be left one layer at a time , At worst, we need 51 Time ( The corresponding hardness is 100).
Square root method : We try every 10 Layer throw once , First time from 10 Layer throw , Second times from 20 Layer throw , The third time from 30 layer … Throw it all the way to 100 layer . The worst-case scenario is at 100 The layers are broken , The number of attempts is 10 + 9 = 19 Time .
Mathematical approach :
Suppose the optimal solution is
xTime , For the first timexThrow eggs on the floor . It can't bex+1layer 、 perhapsx-1Layer throw , Because if the egg breaks , Then we needx+1Attempts to 、x-1Attempts to ;x+1>x, It's not the optimal solution ,x-1If the conditions are met , bexIt's not the optimal solution , contradiction ( In fact, there are still cases to be considered but not broken , So we can't takex-1).If it's not broken , The problem becomes two eggs from
100-xThrow it down the first floor , It is required that the number of attempts should not exceedx-1Time , Therefore, it is necessary tox+x-1Floor throwing .So there is :
x+(x-1)+...+1>=100, Round up , You knowx=14.So at worst , The minimum need to throw
14You can measure the hardness of an egg .
Question 3
nfloor ,mAn egg , To test the hardness of an egg , How many times do you need to throw ?
analysis
This is a dynamic programming problem .
Please refer to for specific explanation :【 Classic algorithm problem 】 The hardness of the egg .
8. Bulb switch
problem
- Yes
nA light bulb , It was bright at first . ConductnWheel operation , The first round will be all 1 Press the multiple bulb switch once , The second time all 2 Press the multiple bulb switch once ,…, How many lights are on at last ? What are the lights ?
analysis
A light bulb
xThe last one is bright * \iff * It is pressed an odd number of times * \iff * Its divisors are odd .Therefore, all the bulbs whose approximate number is an odd number are bright , such as
5A light bulb is pressed5Time ,1、4The light bulb is on , because1Only1This is a divisor ,4Yes1、2、4Three divisors .Next, consider the characteristics of odd data : If a number N The prime factor can be decomposed into p 1 α 1 ∗ p 2 α 2 ∗ . . . ∗ p k α k p_1^{\alpha_1}*p_2^{\alpha_2}*...*p_k^{\alpha_k} p1α1∗p2α2∗...∗pkαk , be N The approximate number of is ( α 1 + 1 ) ∗ ( α 2 + 1 ) ∗ . . . ∗ ( α k + 1 ) (\alpha_1+1)*(\alpha_2+1)*...*(\alpha_k+1) (α1+1)∗(α2+1)∗...∗(αk+1) . Must have α i + 1 \alpha _ i + 1 αi+1 Must be an odd number , therefore α i \alpha_i αi It must be an even number , therefore
NIt's a total square .It is proved that if a number
NThe number of divisors of is odd , Then it is a perfect square number . And vice versa ( for example x = y 2 x = y^2 x=y2, Only divisoryonce , The rest are in pairs ).So the final answer to this question is
1~nThe number of complete squares in .
9. The probability of forming a triangle
problem
- Given a length of
1The rope of , You can select two points from which to truncate , Turn into three paragraphs , What is the probability of forming a triangle ?
analysis
- Suppose the coordinates of the two selected points are
y、x(y<x), Here's the picture :

- You need to meet ( The sum of the two sides is greater than that of the third side ):
{ 1 − y > y x > 1 − x y + ( 1 − x ) > x − y \begin{cases} 1 - y > y \\ x > 1 - x \\ y + (1 - x) > x - y \end{cases} ⎩⎪⎨⎪⎧1−y>yx>1−xy+(1−x)>x−y
- Simplification , Yes :
{ y < 1 2 x > 1 2 y > x − 1 2 \begin{cases} y < \frac{1}{2} \\ x > \frac{1}{2} \\ y > x - \frac{1}{2} \end{cases} ⎩⎪⎨⎪⎧y<21x>21y>x−21
Method 1 : Linear programming
- The linear programming region corresponding to the above inequality is as follows :

- Green and orange are the legal total area , Orange is the area that can form a triangle , Therefore, it should be changed to
1/4.
Method 2 : Double integral
- The probability corresponds to the following integral :
∫ 1 2 1 ∫ x − 1 2 1 2 d y d x / ∫ 0 1 ∫ 0 x d y d x = 1 8 / 1 2 = 1 4 \int _{\frac{1}{2}} ^{1} \int _{x-\frac{1}{2}} ^{\frac{1}{2}} dy \ dx \quad / \quad \int _{0} ^{1} \int _{0} ^{x} dy \ dx \\ = \frac{1}{8} / \frac{1}{2} = \frac{1}{4} ∫211∫x−2121dy dx/∫01∫0xdy dx=81/21=41
- explain : Some reference websites : Check the common intelligence questions in the interview .
边栏推荐
- 数据库全量SQL分析与审计系统性能优化之旅
- d的扩大@nogc
- leetcode:890. 查找和替换模式【两个dict记录双射(set)】
- (14)Blender源码分析之闪屏窗口显示软件版本号
- 初中学历,从不到3K,到月薪30K+,不设限的人生有多精彩
- 循环链表和双向链表—课上课后练
- d的自动无垃集代码.
- How to build your own website (using the pagoda panel)
- 【图像检测】基于深度差分和PCANet实现SAR图像变化检测附matlab代码
- Tomato learning notes-stm32 SPI introduction and Tim synchronization
猜你喜欢

Some operations of MATLAB array

“我被大厂裁员了”

platform driver

Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported

Upload file (post form submission form data)

Postman splice replacement parameter loop call interface

企业微信官方 加解密库 PHP7版本报错 mcrypt_module_open 未定义方法 并且被PHP抛弃 解决方法使用 openssl解决

Solution: unsatisfieddependencyexception: error creating bean with name 'authaspect':

descheduler 二次调度让 Kubernetes 负载更均衡

8. 表单标签
随机推荐
Freshmen are worried about whether to get a low salary of more than 10000 yuan from Huawei or a high salary of more than 20000 yuan from the Internet
libprint2
How to update kubernetes certificates
sql server 2019安装出现错误,如何解决
Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]
Whether the modification of basic type and reference type is valid
Node. Detailed installation tutorial of CPM and cnpm (including error resolution)
Leetcode: Sword finger offer 66 Build product array [application of pre and post infix]
Are you still using like+% for MySQL fuzzy query?
VSCode常用插件
Deep and detailed analysis of PHP one sentence Trojan horse
Throw away the ugly toast. The movable toast is more interesting
Recommend 17 "wheels" to improve development efficiency
About session Getattribute, getattribute error
lambda 函数完美使用指南
Install MySQL tutorial
esp32 hosted
Android studio uses database to realize login and registration interface function
Idea common shortcut keys
libprint2