Share a logic interview question and see if you can answer it correctly!

Release: 2022-03-09 10:52:21
forward
2403 people have browsed it

This article will share with you a logic interview question (with analysis) whose wrong answer has spread all over the Internet. You can analyze it against yourselves to see if you can answer it correctly!

01 Origin of the story

100 people answered five questions, 81 people answered the first question correctly, 91 people answered the second question correctly, 85 people answered the third question correctly, and 79 people answered the fourth question correctly. , 74 people answered the fifth question correctly.

People who answer three or more questions correctly are considered to have passed. So how many of these 100 people have passed?

Share a logic interview question and see if you can answer it correctly!

02 Think about small scale, two questions AB

First consider if there are only two questions AB, 100 people, first reaction It's done in a collection way.

Share a logic interview question and see if you can answer it correctly!

There are only the above three situations in total. The first one is illegal if the number of people is greater than 100, so only the latter two situations exist.
The following conclusion can be drawn:

  • There are at least 72 people and a maximum of 81 people who answered questions AB at the same time;

  • At the same time The maximum number of people who got questions AB and AB wrong was 9 people, and the minimum number was 0 people.

It seems that we have found the pattern, so we will further expand the data scale according to this idea and consider the three ABC questions.

03 Expand the scale, ABC three questions

First consider the relationship between each two questions.

Share a logic interview question and see if you can answer it correctly!

Then synthesize the relationship between the three questions. Wait, it seems a bit complicated. This is not linear complexity. Sorry, little K’s IQ is a bit insufficient and he is autistic.

Share a logic interview question and see if you can answer it correctly!

Is Little K ready to give up? NO, never say give up. Sometimes, don’t hit the wall and never look back. Based on Xiao K’s years of experience, if the pattern you find is not obvious or very complicated, it usually means you are on the wrong track, so you should consider switching your way of thinking at this time.

04 Switch thinking

The above are all positive thinking, but it is difficult to deal with, so you can think in reverse.

Share a logic interview question and see if you can answer it correctly!

As long as you make 3 wrong questions, you will fail. There are 19 9 15 21 26 = 90 wrong questions in total. Then 90/3 = 30, then at most 30 people will fail. , so at least 70 people pass, perfect, and call it a day.

Wait always feels a bit weird, not because it is too simple, but because my intuition about the amount of information tells me that this solution ignores a lot of information.

Only the total number is used, but the distribution of the number of wrong questions for the 5 questions is not used. Then just tell you that there are 90 errors in total. Why do you have to tell the specific number separately? Is this really just misleading information?

05 Extreme thinking

According to the above solution, since you don’t care about the specific distribution, use extreme thinking to construct special data. For example, all wrong questions are concentrated in question A.

Share a logic interview question and see if you can answer it correctly!

There are still 90 questions wrong in total, but everyone got 4 questions right, so 100 people should have passed, and they are autistic again.

At this time, I think there should be a barrage spirit about to jump out.

Share a logic interview question and see if you can answer it correctly!

Little K: What you said makes sense, but I am speechless.
I won’t bullshit you, let’s think about it further. This counterexample illustrates one point: wrong questions cannot be shared evenly at will, so let’s start from this point.

06 Wrong questions are evenly distributed

First look at the distribution of errors.

Share a logic interview question and see if you can answer it correctly!

How to distribute these wrong questions to the most people.

For the convenience of analysis, let’s first write a simple example. For example, the distribution of wrong questions is 7, 8, 9, 10, and 11.

The first allocation:

  • Assign A, B, and C to 7 people

  • Assign C, D, Assign E to 2 people

  • Assign B, D, and E to 1 person

A total of 7 2 1=10 people can be assigned.

Share a logic interview question and see if you can answer it correctly!

In the second type, priority is given to B, C, and D, a total of 11 people.

Share a logic interview question and see if you can answer it correctly!

The third type, priority is given to C, D, and E, a total of 12 people.

1Share a logic interview question and see if you can answer it correctly!

#Here we have discovered the pattern. Prioritizing the three largest channels will get more people. During the allocation process, the largest three orders will change dynamically, which inspires the idea of ​​greed.

  • Sort the wrong questions from largest to smallest;

  • Assign the top 3 largest questions to one person each time, and then reorder.

Repeat the above steps until finally no three numbers that are not 0 can be found, that is, it becomes X,0,0,0,0 or X,Y,0,0,0.

07 Abstract

Conversion problem: There are 5 rectangles, the order can be arbitrary. To cut out N rectangles with a width of 3, the overall superposition must be as high as possible. What is the highest?
You taste it, you taste it carefully, is this the same problem? So start with the top 3 and chip away at it, haha.

1Share a logic interview question and see if you can answer it correctly!

08 The truth emerges

Back to the original question, how many people are there at least? Pass code test results.

8.1 Code Implementation

int main() {
    int a[5], ans = 0;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
    }
    sort(a, a + 5, compare);
    while (a[2] > 0) {
        a[0]--;
        a[1]--;
        a[2]--;
        sort(a, a + 5, compare);
        ans++;
        for (int i = 0; i < 5; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
    cout << "ans=" << ans << endl;

    return 0;
}
Copy after login

8.2 Data Test

25 20 18 15 9 
24 19 17 15 9 
23 18 16 15 9 
22 17 15 15 9 
21 16 15 14 9 
20 15 14 14 9 
19 14 14 13 9 
18 13 13 13 9 
17 13 12 12 9 
16 12 12 11 9 
15 11 11 11 9 
14 11 10 10 9 
13 10 10 9 9 
12 9 9 9 9 
11 9 9 8 8 
10 8 8 8 8 
9 8 8 7 7 
8 7 7 7 7 
7 7 7 6 6 
6 6 6 6 6 
6 6 5 5 5 
5 5 5 5 4 
5 4 4 4 4 
4 4 4 3 3 
3 3 3 3 3 
3 3 2 2 2 
2 2 2 2 1 
2 1 1 1 1 
1 1 1 0 0 
0 0 0 0 0 
ans=30
Copy after login

So at most 30 people fail, and at least 70 people pass. Although the answers are the same, the way of thinking is different.

09 Summary

You should think more deeply about seemingly simple questions, maybe you will find different conclusions. And don’t easily believe other people’s analysis. 90% of the people on the Internet are wrong about this issue. You can also check whether my analysis is rigorous. If you have any questions, please leave a message and give feedback. Thank you.

Related recommendations: "C Language Video Tutorial", "PHP Video Tutorial"

The above is the detailed content of Share a logic interview question and see if you can answer it correctly!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:微信-小K算法
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template