{"id":161,"date":"2022-04-27T20:18:23","date_gmt":"2022-04-27T20:18:23","guid":{"rendered":"https:\/\/algocademy.com\/blog\/?p=161"},"modified":"2024-10-12T13:15:53","modified_gmt":"2024-10-12T13:15:53","slug":"how-to-pass-your-coding-interview-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/algocademy.com\/blog\/how-to-pass-your-coding-interview-a-step-by-step-guide\/","title":{"rendered":"How to Pass your Coding Interview, a step by step guide"},"content":{"rendered":"\n<p>Communication is key to passing your FAANG interview.<\/p>\n\n\n\n<p>Involve the interviewer as if they are your coworker.<\/p>\n\n\n\n<p>Before you code, read the problem statement out loud.<\/p>\n\n\n\n<p>If you&#8217;re unsure how the input leads to the output, you don&#8217;t understand the problem. Ask the interviewer for clarification.<\/p>\n\n\n\n<p>Give an input test case and expected output.<\/p>\n\n\n\n<p>Ask the interviewer if it&#8217;s correct. If it is, you won&#8217;t misinterpret the question.<\/p>\n\n\n\n<p>Solving the right problem is essential!<\/p>\n\n\n\n<p>Talk about the algorithm you&#8217;re going to use.<\/p>\n\n\n\n<p>Mention out loud what you&#8217;re thinking.<\/p>\n\n\n\n<p>Clarify if it&#8217;s a brute force method or why it&#8217;s optimal or not in terms of space and time complexity.<\/p>\n\n\n\n<p>Ask your interviewer if they want you to code that solution.<\/p>\n\n\n\n<p>They&#8217;ll let you know if they want a better approach.<\/p>\n\n\n\n<p>While you&#8217;re coding, explain what each line of code is doing.<\/p>\n\n\n\n<p>Mention what part of the algorithm you&#8217;re currently addressing.<\/p>\n\n\n\n<p>If your algorithm needs binary search, reference the part of your algorithm you&#8217;re at as you&#8217;re coding that portion.<\/p>\n\n\n\n<p>After completing a portion of the code, confirm with the interviewer if they understand what you wrote so far.<\/p>\n\n\n\n<p>If they don&#8217;t confirm or say anything, dry run your code with a sample test case.<\/p>\n\n\n\n<p>If there&#8217;s a mistake, you&#8217;ll catch it here.<\/p>\n\n\n\n<p>If they don&#8217;t understand what you wrote, you likely wrote overly complicated code.<\/p>\n\n\n\n<p>Talk about optimizations and bottlenecks as you go.<\/p>\n\n\n\n<p>There was already agreement on the algorithm you would write, so you don&#8217;t need to optimize on the spot.<\/p>\n\n\n\n<p>Mention as you&#8217;re coding if any portion is suboptimal, and let them know you&#8217;ll come back to it afterward.<\/p>\n\n\n\n<p>You don&#8217;t have to code the perfect solution on the first iteration.<\/p>\n\n\n\n<p>Start your solution with the heavy part of the algorithm.<\/p>\n\n\n\n<p>Point out what you&#8217;re going to code later \u2014 for instance, an isCellValid function.<\/p>\n\n\n\n<p>It&#8217;s not over when you finish writing the algorithm.<\/p>\n\n\n\n<p>We don&#8217;t know if it works or not with the test cases we wrote.<\/p>\n\n\n\n<p>We don&#8217;t know what the interviewer wants you to do now.<\/p>\n\n\n\n<p>So ask instead of assuming what you should be doing.<\/p>\n\n\n\n<p>Ask the interviewer if they prefer you to dry run your code against the example inputs.<\/p>\n\n\n\n<p>Dry run your code against the example inputs.<\/p>\n\n\n\n<p>Go through your code and reference again what portion of the algorithm your code is covering line by line.<\/p>\n\n\n\n<p>Yes, line by line.<\/p>\n\n\n\n<p>As you&#8217;re going through, talk about the state of the output as you go along.<\/p>\n\n\n\n<p>Exactly how a debugger shows you the state of all variables.<\/p>\n\n\n\n<p>And you iterate line by line, watching the variables.<\/p>\n\n\n\n<p>If anything is unexpected, mention you&#8217;re going to fix it and work on it.<\/p>\n\n\n\n<p>The rest of the code is invalid if you&#8217;ve made a mistake, and you don&#8217;t need to discuss it further.<\/p>\n\n\n\n<p>Repeat until you&#8217;ve fixed all your bugs.<\/p>\n\n\n\n<p>Do this for all inputs given.<\/p>\n\n\n\n<p>Or even better, try out some edge cases as well.<\/p>\n\n\n\n<p>Optimize your code further.<\/p>\n\n\n\n<p>If there are bottlenecks in your code, point them out.<\/p>\n\n\n\n<p>Describe why the bottleneck is there and what you&#8217;re doing to optimize it.<\/p>\n\n\n\n<p>Talk aloud about what you&#8217;re thinking and why specific approaches do or don&#8217;t work.<\/p>\n\n\n\n<p>When you come up with an improved solution, ask the interviewer if they&#8217;re happy with that approach.<\/p>\n\n\n\n<p>They&#8217;ll let you know if they want you to implement it or not.<\/p>\n\n\n\n<p>At this point, they&#8217;ll probably ask about space and running time analysis.<\/p>\n\n\n\n<p>The mistake everyone makes when asked about time and space complexities is just stating it.<\/p>\n\n\n\n<p>Don&#8217;t answer without showing your work.<\/p>\n\n\n\n<p>Iterate over the major components of your algorithm and compute and explain the time complexity.<\/p>\n\n\n\n<p>You can write a comment stating the time complexity for each significant chunk of code.<\/p>\n\n\n\n<p>Add those together and formulate the final time complexity.<\/p>\n\n\n\n<p>As for space, track your data structures, and figure out the total and extra space used.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Communication is key to passing your FAANG interview. Involve the interviewer as if they are your coworker. Before you code,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1401,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,23],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-interviews","category-problem-solving"],"_links":{"self":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":7,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions\/168"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/media\/1401"}],"wp:attachment":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}