search
HomeBackend DevelopmentC#.Net TutorialShare a logic interview question and see if you can answer it correctly!

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;
}

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

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!

Statement
This article is reproduced at:微信-小K算法. If there is any infringement, please contact admin@php.cn delete
Is C# .NET Right for You? Evaluating its ApplicabilityIs C# .NET Right for You? Evaluating its ApplicabilityApr 13, 2025 am 12:03 AM

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

C# Code within .NET: Exploring the Programming ProcessC# Code within .NET: Exploring the Programming ProcessApr 12, 2025 am 12:02 AM

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# .NET: Exploring Core Concepts and Programming FundamentalsC# .NET: Exploring Core Concepts and Programming FundamentalsApr 10, 2025 am 09:32 AM

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing C# .NET Applications: Unit, Integration, and End-to-End TestingTesting C# .NET Applications: Unit, Integration, and End-to-End TestingApr 09, 2025 am 12:04 AM

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

Advanced C# .NET Tutorial: Ace Your Next Senior Developer InterviewAdvanced C# .NET Tutorial: Ace Your Next Senior Developer InterviewApr 08, 2025 am 12:06 AM

Interview with C# senior developer requires mastering core knowledge such as asynchronous programming, LINQ, and internal working principles of .NET frameworks. 1. Asynchronous programming simplifies operations through async and await to improve application responsiveness. 2.LINQ operates data in SQL style and pay attention to performance. 3. The CLR of the NET framework manages memory, and garbage collection needs to be used with caution.

C# .NET Interview Questions & Answers: Level Up Your ExpertiseC# .NET Interview Questions & Answers: Level Up Your ExpertiseApr 07, 2025 am 12:01 AM

C#.NET interview questions and answers include basic knowledge, core concepts, and advanced usage. 1) Basic knowledge: C# is an object-oriented language developed by Microsoft and is mainly used in the .NET framework. 2) Core concepts: Delegation and events allow dynamic binding methods, and LINQ provides powerful query functions. 3) Advanced usage: Asynchronous programming improves responsiveness, and expression trees are used for dynamic code construction.

Building Microservices with C# .NET: A Practical Guide for ArchitectsBuilding Microservices with C# .NET: A Practical Guide for ArchitectsApr 06, 2025 am 12:08 AM

C#.NET is a popular choice for building microservices because of its strong ecosystem and rich support. 1) Create RESTfulAPI using ASP.NETCore to process order creation and query. 2) Use gRPC to achieve efficient communication between microservices, define and implement order services. 3) Simplify deployment and management through Docker containerized microservices.

C# .NET Security Best Practices: Preventing Common VulnerabilitiesC# .NET Security Best Practices: Preventing Common VulnerabilitiesApr 05, 2025 am 12:01 AM

Security best practices for C# and .NET include input verification, output encoding, exception handling, as well as authentication and authorization. 1) Use regular expressions or built-in methods to verify input to prevent malicious data from entering the system. 2) Output encoding to prevent XSS attacks, use the HttpUtility.HtmlEncode method. 3) Exception handling avoids information leakage, records errors but does not return detailed information to the user. 4) Use ASP.NETIdentity and Claims-based authorization to protect applications from unauthorized access.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools