Thursday, November 14, 2019
How To Get Un-Stuck During a Tricky Coding Interview Problem
How To Get Un-Stuck During a Tricky Coding Interview Problem How To Get Un-Stuck During a Tricky Coding Interview Problem Whiteboard freeze - t hat moment when youâre working through a tricky coding interview problem, and⦠you have no idea what the next step is. Your mind just goes totally blank. Ugh. The good news? It happens to the best of us. Hereâs how to get back on track. In a way, getting stuck like this is supposed to happen. I f you donât struggle at all with a question and just breeze right through it, your interviewer might just say âHm, this candidateâs probably already seen this question before⦠letâs just throw it out and try another one.â Seriously, Iâve heard several interviewers say they do that! Hereâs why: They want to see you get stuck . Because they want to see what you do when you donât know the answer. Put another way, your interviewer is more interested in seeing your problem-solving skills than they are in seeing how much you know right now . So remember that getting stuck doesnât mean youâre not good enough. It just means youâre in the part of the interview where youâre stuck. Thatâs supposed to happen - so just dig in! Write out a sample input on the whiteboard. (Or, if itâs a phone interview, on your shared code editor). If itâs an array sorting problem, actually write out a list of numbers. If itâs a tree or graph search problem⦠draw a tree or graph. Make your sample input short-ish. Not so short that itâs an edge case , but not so long that itâll be too tedious to solve the whole problem. Then, solve the problem by hand with that sample input. Step by step. Sort the array. Traverse the graph. Notice what steps youâre taking. Think through how to write out those steps as code. And look out for any repeat work youâre doing as you solve the problem. If thereâs repeat work, itâs likely thereâs an optimization you can make to speed up your algorithm. Youâd be surprised how often this leads you to a breakthrough. â I need to keep track of a bunch of stuff, and occasionally grab the thing I put in most recentlyâ¦â You need a stack! âI need to store a bunch of relationships between a bunch of thingsâ¦â You need a graph! Even if you donât think your issue is that you should be using a helpful data structure, it just might be. So walk through the main ones real quick, and see if any of them would help: Remember: a lot of coding interview problems are intended to take the better part of an hour to solve, so it makes sense that the solution wouldnât jump out at you immediately. Itâs important to keep in mind that m Most of these problems have parts . Thereâs a simpler version of the problem, and then a twist that makes it a little harder. And then another twist that makes it harder still. Some interviewers walk you through that process. They ask you the simple version of the problem first, and when you solve that they add the first twist. But some interviewers just throw the already-twisted version of the problem at you all at once. In that situation, you need to come up with your own way of breaking the problem down into steps - s o donât be shy about âun-twistingâ the problem a little bit. For example: Not sure how to find the kth-largest number in an array? Start by thinking about how to find the largest. Then adapt that approach to find the second largest. Then the 10th largest. Then, finally, the kth-largest. Nothing gets you un-stuck like having some well-exercised neural pathways that are already accustomed to âcoding interview thinking.â After all, itâs a skill like any other. With practice, it gets easier and faster. Of course, if youâre in the middle of an interview, practice isnât going to help you anymore. Itâs too late. But youâre not in the middle of an interview right now, are you? Youâre reading this article. Looks like you have a few minutes to read something online. So go check out some coding interview practice problems - by the time your next interview comes up, youâll be glad that you did ! Parker Phinney is the CEO of Interview Cake , which makes free guides and online courses on how to pass coding interviews.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.