Friday, December 13, 2019

How To Get Un-Stuck During a Tricky Coding Interview Problem

How To Get Un-Stuck During a Tricky Coding Interview ProblemHow To Get Un-Stuck During a Tricky Coding Interview Problem Whiteboard freeze - t hat moment when youre 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. Heres how to get back on track.In a way, getting stuck like this is supposed to happen. I f you dont struggle at all with a question and just breeze right through it, your interviewer might just say Hm, this candidates probably already seen this question before lets just throw it out and try another one. Seriously, Ive heard several interviewers say they do thatHeres why They want to see you get stuck . Because they want to see what you do when you dont 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 remem ber that getting stuck doesnt mean youre not good enough. It just means youre in the part of the interview where youre stuck. Thats supposed to happen - so just dig inWrite out a sample input on the whiteboard. (Or, if its a phone interview, on your shared code editor). If its an array sorting problem, actually write out a list of numbers. If its a tree or graph search problem draw a tree or graph. Make your sample input short-ish. Not so short that its an edge case , but not so long that itll be too tedious to solve the whole problem.Then, solve the problem by greifhand with that sample input. Step by step. Sort the array. Traverse the graph. Notice what steps youre taking. Think through how to write out those steps as code. And look out for any repeat work youre doing as you solve the problem. If theres repeat work, its likely theres an optimization you can make to speed up your algorithm.Youd 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 stackI need to store a bunch of relationships between a bunch of things You need a graphEven if you dont 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 helpRemember 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 wouldnt jump out at you immediately. Its important to keep in mind that m fruchtwein of these problems have parts . Theres 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 dont 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, its a skill like any other. With practice, it gets easier and faster.Of course, if youre in the middle of an interview, practice isnt going to help you anymore. Its too late. But youre not in the middle of an interview right now, are you? Youre 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, youll 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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.