TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

I failed a Twitter interview

60 pointsby mostelatoover 11 years ago

31 comments

acchowover 11 years ago
This question involves an &quot;a-ha&quot; moment (for the linear-time solution) and was thus banned from interviews at Google last year.<p>Don&#x27;t use questions involving eureka moments. They reveal nothing about the candidate.<p>Edit: It should be noted that this question was used for a long time at Google, Microsoft, and many other places. It&#x27;s a terrible question.
评论 #6640130 未加载
评论 #6640065 未加载
评论 #6643047 未加载
评论 #6640076 未加载
DigitalSeaover 11 years ago
No offence to Twitter, but this is a seriously bad way of hiring developers. What are you trying to recruit mathematics scholars as developers? When will companies like Twitter learn not all great developers are math geniuses? I didn&#x27;t even get a college education to get where I am, I failed maths in school as well, but I can code, so what does that mean? I think it means nothing in the greater scheme of things. By the sounds of it the author got a better position in the end, I&#x27;d rather be working at Amazon who are solving much better problems than Twitter ever will likely solve anyway.<p>If a company (no matter how great they were) tried asking me these kinds of questions, I would immediately stop the interview and thank them for the opportunity.
评论 #6640126 未加载
评论 #6640169 未加载
评论 #6640136 未加载
评论 #6640097 未加载
评论 #6640613 未加载
johnchristopherover 11 years ago
Google cache: <a href="http://webcache.googleusercontent.com/search?client=ubuntu&amp;channel=fs&amp;q=cache%3Ahttp%3A%2F%2Fqandwhat.apps.runkite.com%2Fi-failed-a-twitter-interview%2F&amp;ie=utf-8&amp;oe=utf-8" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?client=ubuntu&amp;c...</a><p>It&#x27;s off-line for me and asking something about installing a server.
评论 #6640415 未加载
评论 #6640116 未加载
评论 #6640141 未加载
评论 #6640068 未加载
huhtenbergover 11 years ago
&gt; <i>The next day I showed this question to my TA, who&#x27;s a PhD student in theoretical computer science. After 40 minutes he was also stuck with nothing.</i><p>That just doesn&#x27;t speak well of this particular PhD. The one-pass solution is rather obvious. I hate puzzle-based interviews with passion, but this is actually a very reasonable question and it does help to tell apart people with &quot;theoretical&quot; computer science skills from those with a bit more practical experience.
评论 #6640137 未加载
评论 #6643363 未加载
评论 #6643863 未加载
评论 #6640144 未加载
评论 #6640143 未加载
评论 #6640142 未加载
评论 #6640140 未加载
djhworldover 11 years ago
I had two phone screenings with Amazon recently and they decided not to continue with my application.<p>It was depressing to me and I felt down for quite a bit, mainly because on the second phone screening I just couldn&#x27;t do the coding task asked. My mind went blank and I probably sounded like a 5 year old struggling through the simplest of questions.<p>It&#x27;s my own fault though, I just got more and more stressed over the preceding weeks reading algorithms textbooks and &quot;CareerCup&quot; tests I think I just burned out.<p>I totally understand that top companies like Amazon and Google can afford to be ruthless and choosy in their interview process, after all, they&#x27;re top companies for a reason, but I guess it just wasn&#x27;t for me
评论 #6640188 未加载
评论 #6640805 未加载
pjanover 11 years ago
I really don&#x27;t get these coding interviews.<p>I can&#x27;t imagine a construction engineering company asking their applicants to do a construction calculation in an interview, and in this case, bad design can actually kill people (as opposed to a bug at twitter).<p>What else does it bring apart from some amusement to the interviewer?
noelwelshover 11 years ago
Twitter failed you with that interview. Unless the job actually does involve performing computational parlour tricks.
评论 #6645161 未加载
softbuilderover 11 years ago
It&#x27;s not you, it&#x27;s them. A rather brilliant acquaintance of mine did the whole fly-to-SF song and dance with them and didn&#x27;t make the cut either. (He got snagged by a wonderful startup soon after though.)<p>What is important to understand here is that these processes are highly variable and there is an element of luck involved. It&#x27;s just the nature of a human-driven process and a complicated organization.
antirezover 11 years ago
I did not read the final solution but this was a little stimulating quiz, so this is my Ruby solution:<p><a href="https://gist.github.com/antirez/7231559" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;antirez&#x2F;7231559</a>
评论 #6640304 未加载
jjacobsonover 11 years ago
So glad Twitter is continuing the tradition of useless interview questions.
susi22over 11 years ago
FYI this algorithm is called the &quot;Water filling algorithm&quot; and is used extensively in Communications to optimize the allocation power for channels.<p>You can get a solution with simple Lagrangian method (which I believe is the linear solution).<p><a href="http://www.eecs.berkeley.edu/~dtse/Chapters_PDF/Fundamentals_Wireless_Communication_chapter5.pdf" rel="nofollow">http:&#x2F;&#x2F;www.eecs.berkeley.edu&#x2F;~dtse&#x2F;Chapters_PDF&#x2F;Fundamentals...</a><p>(pages 183 - 185)
curiousDogover 11 years ago
Did they actually call you back with a rejection? Sorry if I missed that in the article. Anyway, at the end of the day, what matters is that you solved it on your own :)
评论 #6640099 未加载
JavascriptManover 11 years ago
This pseudo-code seems to be with only one pass no ? Can someone find a counter-example ?<p><pre><code> overall_max=0 index_of_overall_max=0 Second_max=0 index_of_second_max=0 Array_of_cumulated_Sum=0 Total=0 for i from left to right if Height(i)&gt;overall_max &#x2F;&#x2F;Water Area between new max and old max Total+=overall_max*(i-index_of_overall_max+1)-(Array_of_cumulated_Sum(i)-Array_of_cumulated_Sum(index_of_overall_max)) overall_max=Height(i); index_of_overall_max=i; Second_max=0; index_second_max=i+1; else if Height(i)&gt;Second_max &#x2F;&#x2F;All the parts on second max is only to not miss the kept water at the end between the overall_max and another local max Second_max=Height(i); index_second_max=i end end if Array_of_cumulated_Sum(i)=Array_of_cumulated_Sum(i-1)+Height(i) end for &#x2F;&#x2F;At the end : water area between second max and overall max Total += Second_max*(index_of_second_max-index_of_overall_max+1)-(Array_of_cumulated_Sum(index_of_second_max)-Array_of_cumulated_Sum(index_of_overall_max)) return Total</code></pre>
segover 11 years ago
Cheer up, kid. That Justin probably didn&#x27;t even know what you were talking about. Calculus is not for everybody. :-j
tiagobrawover 11 years ago
Once I failed at a google interview... I got 2 answers right but I couldn&#x27;t answer a third math related question (because the time was over).<p>The recruiter asked me what was the maximum number of edges on a graph without cycles.<p>When I was on my way home (in a bus) I had this &quot;a-ha&quot; moment.<p>Well, they lost a great computer scientist in their team! :P
granttimmermanover 11 years ago
I have my phone interview with Twitter next week.<p>I remember last year I got a similar question from both Twitter and Fb. It&#x27;s really just a buckshot. Sometimes you&#x27;ll get a problem that comes easy and sometimes you&#x27;ll be sitting there dumbstruck.<p>Best of luck with your future interviews.
etlerover 11 years ago
I think this is a terrible way to conduct a phone interview. I think about code visually, and this is a very visual question, so thinking about this entirely in my head is way harder than writing it down. I&#x27;d be worried that having a computer in front of me would give the wrong impression, if typing sounds are heard on the phone, and I wouldn&#x27;t want to discount a potential great developer just because they were too nervous to ask if it were ok to grab a pen and paper. With all the ways we can communicate now, it seems archaic to ask someone to think through and explain their code over the phone.
评论 #6644720 未加载
iliaznkover 11 years ago
I wonder if Jack Dorsey could solve rhat right.
dhruvaroraover 11 years ago
Wait. I fail to understand why this counts as a reason for rejection. You attempted a solution, which the interviewer backed up (I assume if you were heading in a completely incorrect direction, he would have told you that), you showed quick thinking (connecting local maximas to the problem) as well as coding competence and basic testing knowledge.<p>Is this not what Twitter desires through its interviews?Because time and again I have heard that companies look and focus on people&#x27;s thought processes more than their exact results.<p>PS: I&#x27;m a college student so I&#x27;m really keen to know how important being 100% accurate is.
isbover 11 years ago
Algorithmic interview questions should ideally have multiple solutions of varying complexity. The &quot;brute force&quot; solution should be obvious to anyone competent enough. If they are able to code it up with reasonable clarity and test cases, that is a good start (think of it as the fizzbuzz level). Good candidates should be able to get to the &quot;ideal&#x2F;aha&quot; solution with some hints. In fact, that process reveals a lot about the candidate. If the candidate doesn&#x27;t &quot;get&quot; to the ideal solution on their own, it shouldn&#x27;t be held against them IMO.
muxxaover 11 years ago
For a single pass from left to right, I think you need to maintain a counter for each y-value:<p><a href="http://codepad.org/W16O9vUB" rel="nofollow">http:&#x2F;&#x2F;codepad.org&#x2F;W16O9vUB</a><p>I actually think this is a good interview question, as playing devils&#x27; advocate and coming up with testcases that will break your initial code is a key programming skill, rather than assuming it is done and moving along.
isbover 11 years ago
In interviews and in general, it usually is a good idea to get a correct yet inefficient solution and then try to optimize it. This usually yields better insights in my experience. Here is a quadratic solution:<p><a href="https://gist.github.com/isbo/7239007" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;isbo&#x2F;7239007</a>
pencilcheckover 11 years ago
I have coded up one pass solution in ruby, check it out!<p><a href="https://gist.github.com/pencilcheck/7252934" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;pencilcheck&#x2F;7252934</a><p>A lot of solutions here doesn’t seem to take account of multiple puddles, my solution does take that into account.
twiceadayover 11 years ago
Here is a novel solution.<p><pre><code> make stack water = 0 for n in columns while stack not empty and n &gt; stack top water += min(stack bottom, n) - stack top pop stack stack push n</code></pre>
bartkappenburgover 11 years ago
This is a really nice and elegant solution: <a href="https://gist.github.com/orukusaki/bb189d9f69ad09e2cd5a" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;orukusaki&#x2F;bb189d9f69ad09e2cd5a</a>
paugayover 11 years ago
Here is my solution in PHP: <a href="https://gist.github.com/paugay/7262417" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;paugay&#x2F;7262417</a>
Joisterover 11 years ago
Here&#x27;s my attempt, in java.<p><a href="https://gist.github.com/Joist/7229807" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;Joist&#x2F;7229807</a>
xentroniumover 11 years ago
How will this solution work for cases like [1,2,1], when there will be no water held?
评论 #6640684 未加载
igor47over 11 years ago
you could solve this with a simple state machine; there&#x27;s no reason to resort to parlour tricks...<p><a href="https://gist.github.com/igor47/7228586" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;igor47&#x2F;7228586</a>
评论 #6640105 未加载
评论 #6640084 未加载
评论 #6640085 未加载
huangc10over 11 years ago
imo, interesting and fun question. Difficult to solve on the spot but not bad when you dive into it with a cup of coffee. Always just keep it simple.
stefan_kendallover 11 years ago
This is an extremely common ACM question. This would heavily bias toward anyone who has competed in the ACM, which is probably the worst metric for hiring ever.