Algorithm data structure interview sharing (i)-a general approach to solving algorithmic problems

Source: Internet
Author: User


First look at a topic: give you an integer array, I want to find out the largest two number, can help me write an algorithm?

get this question , how will everyone think of the way to solve it? I have seen a lot of classmates answer is, first sort, take the maximum of two number is good. So then our question becomes how to sort the integer array. We have a lot of methods, bubble sort, quick sort and so on. Chances are, the interviewer will let you start writing specific sorting algorithms. Of course, some experienced classmates might say, sort me directly call the sort method just fine ha.


In fact, these two situations are not right and wrong points, but did not knock open the interviewer's heart, nor give a person in front of the bright, let himself stand out .

Look at this question again, if I am the interviewer, first I want to know your understanding of this problem is what? How are you going to solve it? Do you have any questions to communicate with me to confirm? If the work is in place, even if the code is flawed, the interviewer may not care, who can not have a ha. Besides, we are still students, experience less, but I have potential.


Well, if you ask, what can I ask?

We all know that communication is very important, no one project can be done by one person. I have some questions for you to refer to:

    1. Integer array, is there a limit to the length of the array? (not raised, basically no limit)

    2. Is the range of numbers in the array known? (not raised, basically no specific range)

    3. Find the largest number, then can I sort it? Can I invoke an existing SDK? (Nonsense, of course, not to write an algorithm?)

    4. Can change the original array order? (If the sort is basically changed, unless you copy an array again)

    5. Is there a requirement for the time complexity and space complexity of the algorithm? (Of course, the smaller the better)

    6. Find the maximum number of two, if there is only one or no number in the array? (What do you think?) One returns one, and the other returns what? 0 or Int.min value, or empty value? Which one is more reasonable)

    7. What if the array is empty? (Return an exception?) Do you want to return the minimum value? Return an empty array? Do you want to return null values in the array?

    8. Returns two numbers, returned with an array? or return with a parameter? (then we return to the data bar)

    9. Returns two numbers, the largest one, the second largest one?

    10. Returns two numbers, is this requirement often changed? (return 3?) Any one? )


I'm sure you can think of more questions . Well, we can imagine that we're going to be talking about this for a few minutes, and of course, there will be an interviewer who will kick the question back to you, let yourself give the answer, and when unreasonable, he may ask why. Then we can only write the best plan according to our own understanding. This blog is to take this example, summed up the solution algorithm and data structure of the general method, the next chapter we will take you together to resolve the problem.

It's just a dry, huh. Solving algorithm and data structure problems generally follow the following 6 steps, while the real code is actually one or two steps.

    1. Make sure you understand the problem and try an example to make sure you understand it correctly

    2. Think about what you can do to solve the problem, which one will you choose, and why?

    3. Explain your algorithm and how to implement it

    4. When writing code, remember, be sure to explain what you're doing.

    5. Take an example, work through your code

    6. Fix defects to ensure that anomalies are taken into account


Of course, if you find a new problem in the middle, we need to put it in time. When we can not write down, we have to go back to the previous example, is not our understanding of the wrong, of course, the interviewer will also be tempted to communicate with you, unless you give up the opportunity yourself.


In the following chapters, we will follow these 6 sections to resolve common algorithms and data structure problems.

All right, welcome to my public number, and my collection .Video Tutorials, data structures and algorithms and BAT,Microsoft Classic algorithm face question counseling。 and our special courses.Sorting Algorithms,featured courses in linked list algorithmsEveryone has a better solution, also welcome to discuss Kazakhstan.


Algorithm data structure interview sharing (i)-a general approach to solving algorithmic problems

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.