Interviewing people was a novelty to me. I was always interviewed. I am well aware that it is difficult for my region and company to attract first-class software talents in China. So I lowered my expectations and asked very few in-depth technical questions, just broad, basic ones. I just need to finally say to the Leader, “This person is ok/good/very good”. As for other ability, comprehensive level, by others check. To this end, in the selection of a single pen test, I particularly heart.
First of all, I didn’t dare to use the widely circulated questions on the Internet, such as those in Leetcode and The Interview Guide for Programmers – they were too difficult! Seriously, very few people can do it perfectly in an hour unless they’ve done it before. I also don’t want others to test my special troublesome algorithm, so I created a special simple. Second, for the most part, Java programmers don’t need to write complex algorithms. On the contrary, the Java layer mainly does interface control, business logic, data flow and so on. It advocates simple and readable code, and tries to use the existing common class library, at the expense of some operational efficiency. Take a complex algorithm problem, test a Java programmer, a bit difficult.
Finally, there is the question of salary and talent gradient. If you don’t have Google’s salary, don’t take Google’s exam. Without Google’s centripetal force, don’t expect google-level talent to interview.
There is a static method called out of class that inserts elements into a List one by one. There’s only one method that can change the contents of this List, which requires that the List be ordered at all times. For example, if I insert 3, 2, 1, 2, I want the List to be 1, 2, 2, 3.
class Solution {
private static List<Integer> sSorted = new LinkedList<>();
public static void addElement(int e) {
// TODO: Insert e to sSorted and make sure sSorted is always sorted.}}Copy the code
I will give 15 minutes, when more often than not I will give 10 minutes more. B: Yes, you can stop here and have a try. I believe that under the relaxed environment of reading the article, I can sort out the idea of this problem in 10~30 seconds.
(Why is the lower limit 10 seconds? Alas…… Accidentally exposed the peak of my IQ. I’ve actually asked some of my colleagues, and they usually come up with the right idea in less than 5 seconds as soon as they understand, including a hardware engineer and a girl who only does communications and documentation.)
Hints In the process, I will gradually give some hints, from the interface to the idea, will actively provide, other basic questions must be answered. If the pure algorithm, C language is the most appropriate, because it does not have what advanced tool class, what complex point have to write their own. Java, on the other hand, has some “base” libraries that are hard to remember. As with the java.util.List, not many people can write out its common interface on paper.
I’m not looking at rote memorization, because in this day and age, very few programmers can program properly when they’re offline. So I will voluntarily provide an incomplete interface List of List.
public interface List<E> extends Collection<E> {
public void add(int location, E object);
public void add(E object);
public void clear(a);
public boolean contains(Object object);
public boolean equals(Object object);
public E get(int location);
public int indexOf(Object object);
public boolean isEmpty(a);
public E remove(int location);
public E set(int location, E object);
public int size(a);
}
Copy the code
I didn’t give a full interface, because giving more would be misleading. In fact, there are only three interfaces that can be used, but I can’t give only three, because it is too obvious and limits the other person’s thinking. So, these are the ones that might be useful. I didn’t comment on it either, because a statement is enough. And IF they ask, I’ll explain.
At first I thought, let’s do a sort test. But on second thought, that was pretty irresponsible. Opposite if the back of a bubble sorting solution, not up to the purpose of examining the technical level, the Boss will not be recognized. In the spirit of “don’t be too obvious”, I want to do insertion sort, and make it so that not many people have seen it before.
Sorting is a basic class of algorithms that a qualified programmer knows at least one of. While most people are good at entry level bubble sort, I prefer insert sort for reasons… You’ll see.
Insert sort is the logical division of an array or list into two parts, one to be sorted and one to be ordered. The ordered section starts with a single element (or none at all), which is then pulled one by one from the sorted section and inserted into the ordered section. When all the elements are inserted into the ordered part, the sorting process is complete.
You see, it’s only N insertions. And this one, I’m only asking you half of the insertion sort algorithm, so you know how to insert.
I often explain insertion sequencing myself during interviews — I can’t afford to backpedal at this point.
This is an Android platform development job, Boss is required to be able to work, do a good job. My recommendations are as follows:
Familiar with Java.
Good communication and presentation skills.
Quick learner, like to continuously expand the knowledge of computer field.
Good coding habits, willing to modify code repeatedly for simplicity and elegance.
I suggest that Boss abandon the requirement of education and years of service, and that technical positions should only look for skills (and other basic abilities), not indirect proof of skills.
Java is the foundation of Android (we don’t play with Kotlin, Scala, React Native, etc.) and if you don’t have a solid language, you have to learn it for at least six months.
I didn’t explicitly ask to look at Android because those things are relatively easy to learn. It only takes a day or two for an inexperienced beginner to figure out what the “four components” or “five layouts” are. If Java is not solid enough, all kinds of visible bugs will emerge endlessly, and the knowledge blind spots will be filled in a year or two.
Communication is a basic skill in the workplace. Lack of clarity can significantly reduce the effectiveness of team communication. And, personally, I think people who can’t articulate can’t write good code. Language clear, logical hierarchy, reflected in the code, is concise, clear.
Learning ability and thirst for knowledge are the basic qualities of a programmer. Because most people’s job is sort of like looking through a bunch of buttons and finding the right one to push; Programmers do this with their eyes closed. Development engineers are usually in a pile of unknown (unread code, unknown interface), into a small part of the known (read code or interface), some additions and modifications, finally achieve external (product managers, designers, test engineers) assigned business goals.
Some professions sell lip service, others sell eloquence. Some professions sell youth, some professions sell flesh (cough, I say is stewardess and move brick, want crooked of go to face a wall). Some professions sell knowledge, others ability.
Programmers, or software developers, sell the ability to learn (and indeed youth and flesh), to learn things quickly, to find buttons hidden off-screen, and to press them correctly. For example, a Command line tool such as Bash is used to type the Command itself instead of looking for the corresponding button on the interface. Programming, implementation, is about finding or creating a solution to a problem and then expressing it in code — you see, doing the opposite of UI and UX design. Continuous learning is the only way to improve efficiency, free yourself from overtime, and save the project from bugs. Therefore, people who are tired of learning can not be good programmers, nor do they work for long.
Coding habits, relatively second. Part of the argument is that it lasts a lifetime, and if you don’t have good habits at the beginning, you can’t change them. Boss thinks so. I don’t think so. I believe that the malleability of coding habits is very high – if you don’t write according to the specification, I don’t give you merge.
However, coding habits, as soft skills of programmers, can be seen from their technical literacy and code quality to a certain extent. As for elegance, I didn’t really dare to expect that.
So, my question is really looking at these four points.
Being able to write, and having no obvious problems, represents a solid foundation in Java.
Understand my description of the topic and confirm with me the details of the topic, which depends on communication skills.
Do not know the List interface, I give you ah; Insert sort won’t, I’ll teach you; What else won’t, you ask — this is a test of learning ability.
Between the lines of code, you can clearly see the coding habits.
Overall, I was sad.
The first one made me sad. When I read his first two lines of code, I couldn’t bear to read further:
private static List<Integer> sSorted = new LinkedList<>();
public static void addElement(int e) {
if (null == sorted) {
sorted.add(e);
}
// I couldn't read more!
Copy the code
The first line does not compile. If he had any knowledge of Java naming conventions, he would never have written sSorted as sorted. (Of course, sSorted is probably not the right name because prefixes like s and m are redundant. I usually follow the general specification of the Android source code, which has such prefixes.
The second line inevitably throws a NullPointerException, and thankfully or sadly, it never executes. According to the addElement interface THAT I have given, and the read interface that can be guessed or asked, sSorted will not be null. This reflects a little problem of communication and understanding ability.
Furthermore, even if sSorted is null because of some bug, it should not be handled here. Instead, it should either throw a NullPointerException, or escape to throw an IllegalStateException. Otherwise, this becomes a hidden bug that does not crash. Abnormal processing cannot be replaced by normal processing. Of course, you can’t replace process control with exception handling.
And, to my disappointment, one of them wrote:
for (int i = 0; i < sSorted.size(); i++) {
if(e == sSorted.get(i)) { sSorted.add(i, e); }}Copy the code
I asked him, what if this element doesn’t exist in the List? What if the List is empty? He was immediately embarrassed, AND SO was I, wondering if I was too bad.
Another answered all my questions as if he had heard them:
if (sSorted.size == 0) {
sSorted.add(e);
return;
}
if (e >= sSorted.get(sSorted.size - 1)) {
sSorted.add(e);
return;
}
if (e <= sSorted.get(0)) {
sSorted.add(0, e);
return;
}
if (sSorted.contains(e)) {
sSorted.add(sSorted.indexOf(e), e);
return;
}
// more...
Copy the code
What does he want to do? Maybe it’s to optimize performance, that’s all. In addition, his understanding of size is the same as the length of an array.
This one is more experienced (30 years old) and has a deeper understanding of Java. He says sorting doesn’t need to be written by hand, there’s an interface in Java. I said, yeah, but I didn’t give you the interface, so if you remember, write it down.
So at the end of that big paragraph about “optimization,” he wrote:
sSorted.add(e);
sSorted.sort(newComp... able() {public boolean? (left, right) {returnright >= left; }});Copy the code
In terms of the idea, insert and then sort, I’m not teasing. Comparable and its interface int compareTo(T another). If I can’t remember, I’m going to look at lambda. But this one? Int compare(T LHS, T RHS) compare(T LHS, T RHS)
But actually, I can hold my nose and read all of this, because I can’t write it by hand. There is no sort method for List.
Arrays and Collections have their own sort, which is a silver bullet utility class, whereas Array and Collection don’t. This is a detail that anyone who uses it knows, and if he knows it, he will remember it correctly, even if he is short of an “S”.
The other guy, who inserts and bubbles sort, writes:
sSorted.add(e);
for (int i = 0, sSorted.size(i) > sSorted.get(e), i++) {
temp = sSorted.get(e);
sSorted.get(e) = sSorted.size(i);
sSorted.size(i) = temp;
}
Copy the code
You read that right, for() is separated.
You read that right, Temp comes out of a crack in the stone.
List.get(e) can be assigned.
List.size(I) can be passed as a parameter.
And two of them just gave up.
One of them was serious, thought for a while, and said, “I don’t want to waste my time.”
I didn’t use the wrong words. He was “serious.” Another in my hand in the past, directly look at two eyes on the hand back, “sort I can’t”, and then look at the phone.
O (╯ / ╰) o
When I write on paper, it takes me about five minutes to think about the details and another five minutes to write them out. (alas…… Accidentally, and exposed their very slow thinking, and very slow writing speed. That’s several times longer than I had expected!
However, with the 15-25 minutes I’ve given, it shouldn’t be too difficult… ?
class Solution {
private static List<Integer> sSorted = new LinkedList<>();
public static void addElement(int e) {
int i;
for (i = 0; i < sSorted.size(); ++i) {
if (e <= sSorted.get(i)) {
break; } } sSorted.add(i, e); }}Copy the code
This is the answer I wrote on the paper myself. (If you’re interested, stop here and think about whether this is optimal.)
@Override
public E get(int location) {
if (location >= 0 && location < size) {
Link<E> link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) { link = link.next; }}else {
for (inti = size; i > location; i--) { link = link.previous; }}return link.data;
}
throw new IndexOutOfBoundsException();
}
Copy the code
This is the implementation of java.util.linkedList on Android (API 23), and the decompilation of the Oracle JDK 1.8 is much the same. In other words, the answer I wrote, while seemingly neat, is not much different from the worst-time order of insert first and then sort, which is O(n2).
If you beat swallows all day long, they peck your eyes! (Revealing the true level.)
I later wrote a reference answer, reluctantly touching some sunscreen on my face. (If you’re interested, think about why this is an improvement. Of course, there must be a better plan.)
class Solution {
private static List<Integer> sSorted = new LinkedList<>();
public static void addElement(int e) {
int i = 0;
for (int j : sSorted) {
if (e <= j) {
break; } ++i; } sSorted.add(i, e); }}Copy the code
(I didn’t include an iterator in the hint list, and I got passed over myself.)
When the interviewer asks a question about the candidate, the candidate is asking the same question about the company.
In order to avoid the impression that the exam questions are too easy, the work is too boring, and the staff (me) is too low, I have prepared some follow-up questions, from the simple to the deep, as a killer.
Why can LinkedList be assigned to a List? Look at polymorphism.
Why does LinkedList<>() write to <> while LinkedList<>() does not? Look at generics.
Why is there an Integer in the List and an int in the List and an int out? (There’s a pit here, but it’s still an Integer.) Look at auto boxing/unboxing for basic data types.
How do I ensure that this unique List is correct when there are multiple calls out there? Look at synchronized and volatile.
How to maintain a separate List for each thread in multi-threaded state? Examine ThreadLocal.
(There are, of course, some Android-related issues.)
I didn’t really want to take an algorithm exam, so I wasn’t even going to ask for an algorithm complexity assessment. The truth is, I often don’t get a chance to ask these questions because few people write about them.
First, the expansion of college enrollment… You know what? Let’s not go that far. The two people who gave up were from the computer school and the software engineering school. Sort write not to come out, actually also can graduate!
Two of them are App developers. When I downloaded their App and found a bunch of bugs, I wanted to put up with it and just ignore it. Why bother with it? Then the phone got hot, stalled, and almost couldn’t light up after the screen went off (a memory leak ate up the RAM and left the system process with no memory available). Finally, after a while, I looked at the power consumption rankings, and after 10 minutes of running, I was at the top, using 17% of power — I was so scared that I uninstalled it immediately. A third party App can block the system into such, ordinary people really can not do.
Two “related majors,” other than computer and software engineering, performed best, though still not listed.
All of them, without exception, have attended some Java and Android training outside the university. The level of these training classes can be seen. The problem is not necessarily the quality of the training, but rather the form of mass talent transformation services — not everyone in the world can be a good coder, even if the job requires just copying and pasting.
Nowadays, many programmers joke that they are “moving bricks” and copying and pasting, but there is more to a programmer’s job than that. Use basic algorithms written by others, and refer to implementation code written by others, just to focus on solving business problems at a higher level of abstraction.
“We don’t write code, we’re just code porters.” Do not take this as an article of faith.
There are also many people who, without Demo, can’t write code, no matter how detailed the API or other materials are given. They can only tinker with what they already have, not create out of thin air.
I recommend three basic Java books:
Think in Java is the most appropriate introduction to the Java language. Many other grammar books are about the change of Java from the perspective of C/C++, or discuss how to use Java from the idea of C++, but the English name of this book directly tells you, please use Java to think and solve problems.
There’s a lot of potholes in Java, and there’s a lot of sugar in Java. If you haven’t read this book, you will make a lot of big mistakes unconsciously.
I started Clean Code when I was writing a little project on my own. Halfway through the project, you can’t even write code! Every day I write code that I can’t read, and I don’t know how to write code that I can read. Speed up after watching, start again will write code. In the end, the code for the second half of the project was completely different from the first half, unlike one person who wrote it, and I refactored it later.
Why don’t I recommend more books? For one thing, I haven’t seen much myself, 囧; Secondly, three books is the limit. According to my experience, recommending three books will get people to read one book, and recommending more than three books will get people to read none.)
I have a friend, also a former colleague, who is studious as lecherous. He spends his weekends reading in a college classroom, and sometimes even takes annual leave to read in the classroom. A book of Java Programming Ideas, read line by line at least three times. Less than two years of work experience, job-hopping three times, now in a ten-billion listed company, annual salary of 300,000, leading ten people.
Investigate its reason, no more than basic knowledge is solid, saliva gush dead interviewer er.
Postscript AS a first-time interviewee, I was only thinking about my favorite thrust… Uh no, insert sort algorithm, I’m sorry for causing unnecessary trouble to others.
I interviewed with a documentation and specifications girl (the aforementioned one). She has a veto, too, and she uses it more often than I do!
At most, I only give blank papers and the App that consumes terrible power. These people reject it directly. This girl, on the other hand, looks at other comprehensive abilities.
In practical work, she is the interface person of requirements, and we need to communicate with her to realize the needs of all parties on our team. So, as soon as she says, “I have a hard time communicating with this person,” he basically says no.
Next time, I’ll change to a simpler one. Why bother coding farmers?
Scan the following TWO-DIMENSIONAL code, timely access to more Internet job interview, Java, Python, crawler, big data and other technologies, and massive data sharing: public account background reply “CSDN” can be free to receive CSDN and baidu Library download services; Public number background reply “information” : you can receive 5T quality learning materials, Java interview test points and Java summary, as well as dozens of Java, big data projects, the information is very complete, you want to find almost all