TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Data Structure and Algorithms Interview Questions for Programmers

198 点作者 javinpaul超过 6 年前

16 条评论

dvt超过 6 年前
I officially refuse to do these in interviews (along with whiteboard coding) anymore and I&#x27;m very upfront about it with hiring managers and recruiters. My reasoning is twofold: (a) I&#x27;m generally not great at these kinds of questions so I think it&#x27;s an unfair disadvantage and (b) I think that my experience, open source contributions, Apress book that my name is on, blog that I often post to, etc. speaks for itself. However, I will <i>gladly</i> do your take-home assignment. I&#x27;d be even more thrilled if we can discuss it during my interview.<p>It&#x27;s kind of how in dating people have deal-breakers (e.g. no smokers, no kids, and so on) -- when looking for a job, this is one of mine.<p>Obviously, the caveat here is huge companies like GOOG, FB, AMZN -- these are big companies that need filters and I completely understand the reasoning behind their process. If I wanted to work there, I would certainly study data structures and algorithms before my interviews.
评论 #18457213 未加载
评论 #18457230 未加载
评论 #18457648 未加载
评论 #18457127 未加载
评论 #18457679 未加载
评论 #18459894 未加载
评论 #18460511 未加载
评论 #18458631 未加载
评论 #18457113 未加载
Waterluvian超过 6 年前
I feel frustrated by the concept of software interview questions but only recently do I think I&#x27;ve figured out why. They feed my impostor syndrome.<p>They&#x27;re often trivia that I&#x27;ll never learn from my job, so if I didn&#x27;t go to school for programming I won&#x27;t know. Or they&#x27;re specific to a domain I&#x27;ll never touch so I won&#x27;t know.<p>I don&#x27;t think they&#x27;re fundamentally bad (I used to), but I&#x27;ve never read one of these without coming out the other side feeling lower about myself.<p>Not sure I have a point. Just wanted to share.
评论 #18457778 未加载
评论 #18457105 未加载
EZ-E超过 6 年前
Why do interviews for dev jobs increasingly becomes a game beaten by &quot;grinding&quot; leetcode or other websites listing questions?<p>It&#x27;s like many companies have given up trying to rank applicants based on actual job experience and skills. &quot;You&#x27;ve created and ran successful software for hundreds of thousands of paying customers? That&#x27;s cool, but if you can&#x27;t write a merge sort implementation on this whiteboard we&#x27;d rather hire the guy that learnt it by heart.&quot;
评论 #18457163 未加载
评论 #18457232 未加载
slimshady94超过 6 年前
I feel like the interviewing grind has become akin to gymming - you go to your mental gym, build up your &#x27;muscles&#x27; by doing pointless repetitive tasks AKA algorithms you&#x27;d never use in real life (probably like how bodybuilders would never need to deadlift 125kgs in their daily life). It doesn&#x27;t directly help you do your job but you know bodybuilders have higher than average fitness levels. So in the same manner, devs grinding leetcode probably have higher &#x27;fitness&#x27; levels than devs who don&#x27;t.
评论 #18457449 未加载
评论 #18457266 未加载
评论 #18457204 未加载
denormalfloat超过 6 年前
Data structures and Algorithms are fun, but more and more I see that general software engineering is something we need. Several useful questions venture too deeply into domain specific things, making them difficult to give to candidates. For example:<p>* Make a simple memory allocator.<p>* Make a simple HTTP Proxy<p>* Make a simple URL parser<p>* Make a simple CSV parser<p>* Make a threadsafe Queue<p>* Design a class to handle exponential backoff<p>None of these are particularly useful, but I think they can let a candidate show off how they can handle a simple problem, and how they modify their code as the problem grows in complexity. Sadly, most of these questions candidates have no familiarity with. I would much rather see it than more O() analysis.
评论 #18457643 未加载
评论 #18457400 未加载
评论 #18457468 未加载
jfultz超过 6 年前
There are various answers which seem a bit sloppy to me. For example, &quot;How do you find the middle element of a singly linked list in one pass?&quot; The answer, without comment, makes a presumption about how to define the &quot;middle&quot; of a list with even length. And it defines a linked list implementation with a magic, invisible head that requires extra code beyond the loop to compensate for. In the &quot;How do you check if two rectangles overlap with each other?&quot; answer, the code will determine that the rectangles which merely coincide at edges or corners are overlapping, without noting that distinction. The vending machine example tries to drive home the point of requirements definition, but the point applies equally to these much simpler examples. I only gleaned maybe 10 examples...maybe I just got &quot;lucky&quot;.<p>Also, the overlapping rectangles example has an error in the explanation. It says &quot;If any of above four conditions is not true then two rectangles are overlapping with each other, as in following diagram first condition is violated, hence rectangle A intersects rectangle B.&quot; This somewhat nonsensical statement refers to a diagram that&#x27;s not there, but furthermore, incorrectly indicates that the rectangles overlap if &quot;any of [the] conditions is not true&quot;, when in fact <i>all</i> of them must be false. The code is correct on this point, but the explanation is wrong.
评论 #18458074 未加载
topkai22超过 6 年前
I&#x27;ve been trying to weed out a lot of these problems from my team&#x27;s interviewing set- they filter for CS students, not practical development knowledge. I can honestly say I&#x27;ve never used a linked list in 15 years of being paid to develop software. I&#x27;ve been pushing interviewers to come up with a problem based on code they&#x27;ve actually written in the past and use that for their interview question.<p>I&#x27;m starting to think I might have better luck having a pre-built some code with some poor practices and asking a candidate to refactor and improve it- evaluating their ability to at least know what clean code is supposed to look like.<p>That being said, I&#x27;m not willing to give up my whiteboard code interviews yet- they are too useful a filter. I still get candidates that sound fine talking about their previous experience and then say things like &quot;oh man, its been a while since I&#x27;ve used arrays&quot; when asked to code.
评论 #18457532 未加载
评论 #18457367 未加载
WalterGR超过 6 年前
I’ve started telling non-techie people that you don’t interview for software engineering jobs: you audition for them.<p>They get it.
评论 #18458051 未加载
评论 #18457802 未加载
LaserToy超过 6 年前
I’m too old. I’m telling recruiters that I will not spend even 5 minutes preparing for the interview. I believe that interviews should be based on what you did, not on your ability to memorize a book of CS problems and solutions.if you a company with good BS department (like google, db,...) you can be arrogant and still have candidates, but if you not them, I highly recommend to rethink how you interview people.
评论 #18459626 未加载
gpderetta超过 6 年前
The &quot;one pass&quot; solution to find the middle of a linked list visits each element twice (or more precisely, it visits half of the elements twice). It is hardly one pass.
评论 #18457726 未加载
评论 #18458269 未加载
tralarpa超过 6 年前
To teach programming, many universities structure their courses &quot;bottom-up&quot;:<p>1. Intro: learning how to implement an algorithm<p>2. Algorithms+datastructures: learning about existing algorithms&#x2F;datastructures and how to design your own, reasoning about complexity<p>3. Program design: how to write larger programs (OO, compiler construction, distributed algorithms, etc.)<p>4. Managing the development process: project management,...<p>Those interview questions are highly annoying because they only cover levels 1+2. Other important technical skills (able to quickly understand code written by others, how to organize programs, etc.) are not tested. The questions are also rather insulting if the candidate has already several years of experience because they suppose that the candidate is still stuck at those lower levels.<p>But even if the goal is to test those lower levels, the questions are highly ineffective. Many of them do not test skills, they test your memory. You either have already heard about the cycle-detection question or you haven&#x27;t. I am surrounded here by very smart people and I doubt that anyone of them would be able to find the answer to that question by themselves in a few minutes.<p><i></i>* The following rant is slightly off-topic:<p>However, I have to say that I am encountering more and more people like the person who posted here yesterday: People who have been programmers for several years and who admit that they have problems with loops and simple datastructures. In my opinion, if you have problems with those levels 1+2, you should not even think about the other levels. Many problems that we have for example in performance and cybersecurity are caused by the fact that most programmers simply don&#x27;t know what they are doing. If you have problems with loops, you will not understand what a buffer overflow is. If you don&#x27;t know what pointers are and how main memory works, you will not understand why your program is slow. And I am saying this as somebody who hates low-level languages like C (although I am quite good at them).<p>I know that this is currently a highly unpopular opinion among certain teachers who are pushing for a &quot;softer&quot; introduction to programming (with a lot of GUI designing and project management right from the beginning) and I have some sympathy for their position (students should not get the impression that CS is only about programming). But at some point you have to learn how a computer works, otherwise you will copy-paste from stackoverflow for the rest of your life.
ricardoreis超过 6 年前
<i>Here are some of the popular array-based coding interview questions for your practice:</i><p><i>How do you find the missing number in a given integer array of 1 to 100? (solution)</i> [1]<p>How do you land a job at &quot;startups like Uber and Netflix; big organizations like Amazon, Microsoft, and Google; and service-based companies like Infosys or Luxsoft&quot;?<p>Easy - by rote memorization. And a healthy sense that it&#x27;s to best not question the basic idiocy behind cargo-cult interview tactics like these.<p>Because apparently genuinely useful critical thinking skills -- beyond such trivial matters such as how to get a better space-time tradeoff on that petabyte-scale fibanocci generator[2] our customer desperately needs you to design a viable POC for <i>right now</i>, on the whiteboard, before lunch -- basically aren&#x27;t needed at these companies.<p>Notes:<p>[1] You think I&#x27;m just being snarky? It&#x27;s famously common out in hedgefund-land for people to get hired more or less on the basis of being able to whip out a deadpan response to &quot;gee-whiz&quot; questions like these. And to get &quot;flushed&quot; for their inability to do the same. Startups aren&#x27;t quite so naively reliant on shibboleth questions of this sort -- but but only slightly so.<p>[2] I&#x27;m being slightly hyperbolic with this example -- but only slightly. I&#x27;ve long since lost count of the number of times been asked &quot;design&quot; questions really only slightly more ridiculous than this example. And as a matter of fact I&#x27;ve been asked an &quot;advanced fibanocci&quot; question -- and apparently received a job offer to a large extent on the basis of my ability to &quot;nail&quot; it -- quite recently
评论 #18458511 未加载
iKevinShah超过 6 年前
I wish I had seen this yesterday. I had an opportunity (interview) and a had a lot of &quot;Oh I know this&quot; but when asked to explain further I was like &quot;Oh...?&quot;
soulwatcher超过 6 年前
I find these questions are a bit too simple and direct. Some of the interview questions I&#x27;ve seen are much more nuanced and often more indirect.
graycat超过 6 年前
Apparently one of the questions was:<p>Q. Given X-Y coordinates of two rectangles, determine if they intersect or not.<p>I&#x27;ll try for an answer -- I looked up nothing, and it took longer to type in the answer than it took to think of it!<p>A. Given positive integers m and n and m points A(i) = (a_i1, a_i2), i = 1, 2, ..., m and B(j) = (b_j1, b_j2), j = 1, 2, ..., n, determine if the convex hull of the points A(i) intersects the convex hull of the points B(j). So, look for a line that has all the points A(i) on one side and all the points B(j) on the other side.<p>Suppose we have numbers u, v, w, and consider the set of all (x,y) such that<p>ux + vy = w<p>Then those points (x,y) form a line, and every line can be written in this form.<p>Then we seek u, v, w so that all the A(i) are on one side of the line and all the B(j) are on the other side. So, without loss of generality, we seek u, v, w so that for all i<p>ua_i1 + va_i2 &gt;= w<p>and for all j<p>ub_i1 + vb_i2 &lt;= w<p>Or, we seek u, v, w to solve the linear program<p>maximize z = u + v + w<p>subject to<p>ua_i1 + va_i2 &gt;= w<p>ub_i1 + vb_i2 &lt;= w<p>for all i, j.<p>The simplex algorithm will determine if this linear program is <i>feasible</i>, that is, if u, v, w exist to satisfy the m + n linear constraints, or not feasible. If the program is feasible, then the two convex hulls are separated by the line the set of all (x,y) such that<p>ux + vy = w<p>Else the linear program is not feasible, no line exists separating the convex hulls, and the two convex hulls overlap.<p>Yes, we could tweak this simple formulation to something a little more involved and, then, determine if the two convex hulls just touch but otherwise don&#x27;t overlap.<p>This solution solves the problem about rectangles in the OP as a special case.<p>Let&#x27;s see: Given a closed convex set C with points A(i), is the convex hull of the points A(i) also in C?<p>Well, the intersection of any collection of closed sets is closed (the union of any collection of open sets are open). The intersection of any collection convex sets is convex. Then, the intersection of any collection of closed, convex sets is closed and convex.<p>The <i>convex hull</i> of a set of points is the <i>smallest</i> closed convex set that contains all the points, that is, the intersection of all closed convex sets that contain all the points and, thus, is closed and convex. Here <i>convex hull</i> is <i>well defined</i> since the intersection is unique. A line in X-Y and one side of that line is closed and convex. So the convex hull of a set of points on the line and some one side of it is closed, convex, and a subset of the line and that side of it. Our algorithm needs this result.<p>Is that a sufficiently good answer?
评论 #18457885 未加载
kamaal超过 6 年前
A more exhaustive list is here:<p><a href="https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;fundamentals-of-algorithms&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;fundamentals-of-algorithms&#x2F;</a><p><a href="https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;data-structures&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.geeksforgeeks.org&#x2F;data-structures&#x2F;</a>