diff --git a/algorithms/README.md b/algorithms/README.md index bbcbab1d..cceea770 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -52,7 +52,7 @@ Use a mix of functional and imperative programming paradigms: - Avoid relying on and mutating global variables. Global variables introduce state. - If you have to rely on global variables, make sure that you do not mutate it by accident. -Generally, to improve the speed of a program, we can either choose a more appropriate data structure/algorithm or use more memory. It's a classic space/time tradeoff. +Generally, to improve the speed of a program, we can either: (1) choose a more appropriate data structure/algorithm; or (2) use more memory. The latter demonstrates a classic space vs. time tradeoff, but it is not necessarily the case that you can only achieve better speed at the expense of space. Also, note that there is often a theoretical limit to how fast your program can run (in terms of time complexity). For instance, a question that requires you to find the smallest/largest element in an unsorted array cannot run faster than O(N). Data structures are your weapons. Choosing the right weapon for the right battle is the key to victory. Be very familiar about the strengths of each data structure and the time complexities for its various operations. @@ -147,7 +147,7 @@ Some helpful utility snippets: #### Study Links - [Demystifying Dynamic Programming](https://medium.freecodecamp.org/demystifying-dynamic-programming-3efafb8d4296) -- [Dynamic Programming – 7 Steps to Solve any DP Interview Problem](http://blog.refdash.com/dynamic-programming-tutorial-example/) +- [Dynamic Programming – 7 Steps to Solve any DP Interview Problem](https://dev.to/nikolaotasevic/dynamic-programming--7-steps-to-solve-any-dp-interview-problem-3870) #### Notes @@ -490,7 +490,7 @@ Recursion is a common approach for trees. When you notice that the subtree probl When using recursion, always remember to check for the base case, usually where the node is `null`. -When you are asked to traverse a tree by level, use depth first search. +When you are asked to traverse a tree by level, use breadth-first search. Sometimes it is possible that your recursive function needs to return two values. diff --git a/algorithms/array.md b/algorithms/array.md index 2d23d258..1fcf6b51 100644 --- a/algorithms/array.md +++ b/algorithms/array.md @@ -1,59 +1,48 @@ Arrays == -- In an array of arrays, e.g. given `[[], [1, 2, 3], [4, 5], [], [], [6, 7], [8], [9, 10], [], []]`, print: `1, 2, 3, 4, 5, 6, 7, 8, 9, 10`. - - Implement an iterator that supports `hasNext()`, `next()` and `remove()` methods. -- Given a list of item prices, find all possible combinations of items that sum a particular value `K`. -- Paginate an array with constraints, such as skipping certain items. -- Implement a circular buffer using an array. -- Given array of arrays, sort them in ascending order. -- Given an array of integers, print out a histogram using the said array; include a base layer (all stars) - - E.g. `[5, 4, 0, 3, 4, 1]` +#### Hard +- Given a set of rectangles represented by a height and an interval along the y-axis, determine the size of its union. ([Solution](https://www.geeksforgeeks.org/divide-and-conquer-set-7-the-skyline-problem/)) +- Given an array, find the longest arithmetic progression. ([Solution](https://www.geeksforgeeks.org/longest-arithmetic-progression-dp-35/)) -``` -* -** * -** ** -** ** -** *** -****** -``` +#### Medium +- Given a list of item prices, find all possible combinations of items that sum a particular value `K`. ([Solution](https://www.geeksforgeeks.org/combinational-sum/)) +- Given an array of integers find whether there is a sub-sequence that sums to 0 and return it. ([Solution](https://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/)) + - E.g. `[1, 2, -3, 1]` => `[1, 2, -3]` or `[2, -3, 1]` +- Trapping rain water: You have an array with the heights of an island (at point 1, point 2 etc) and you want to know how much water would remain on this island (without flowing away). ([Solution](https://www.geeksforgeeks.org/trapping-rain-water/)) -- Given an array and an index, find the product of the elements of the array except the element at that index. -- Given a set of rectangles represented by a height and an interval along the y-axis, determine the size of its union. -- Given 2 separate arrays, write a method to find the values that exist in both arrays and return them. -- Given an array of integers find whether there is a sub-sequence that sums to 0 and return it. - - E.g. `[1, 2, -3, 1]` => `[1, 2, -3]` or `[2, -3, 1]`. -- Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index. Discuss the runtime of the algorithm and how you can be sure there would not be any infinite loops. -- Given an array of non-negative numbers, find continuous subarray with sum to S. - - [Source](http://blog.gainlo.co/index.php/2016/06/01/subarray-with-given-sum/). -- Given an array of numbers list out all triplets that sum to 0. Do so with a running time of less than O(n^3). - - [Source](http://blog.gainlo.co/index.php/2016/07/19/3sum/). -- Given an array of numbers list out all quadruplets that sum to 0. Do so with a running time of less than O(n^4). -- Given an array of integers, find the subarray with the largest sum. Can you do it in linear time. - - Maximum subarray sum problem. -- You have an array with the heights of an island (at point 1, point 2 etc) and you want to know how much water would remain on this island (without flowing away). - - Trapping rain water question. -- Given an array containing only digits `0-9`, add one to the number and return the array. - - E.g. Given `[1, 4, 2, 1]` which represents `1421`, return `[1, 4, 2, 2]` which represents `1422`. -- Find the second maximum value in an array. -- Given an array, find the longest arithmetic progression. -- Rotate an array by an offset of k. -- Remove duplicates in an unsorted array where the duplicates are at a distance of k or less from each other. -- Given an unsorted list of integers, return true if the list contains any duplicates within k indices of each element. Do it faster than O(n^2). -- Given an unsorted list of integers, return true if the list contains any fuzzy duplicates within k indices of each element. A fuzzy duplicate is another integer within d of the original integer. Do it faster than O(n^2). +#### Easy +- Implement a circular buffer using an array. ([Solution](https://www.geeksforgeeks.org/circular-queue-set-1-introduction-array-implementation/)) +- Given an array of integers, print out a histogram using the said array; include a base layer (all stars) ([Solution](https://www.geeksforgeeks.org/program-make-histogram-array/)) +- Given an array and an index, find the product of the elements of the array except the element at that index. ([Solution](https://www.geeksforgeeks.org/a-product-array-puzzle/)) +- Given 2 separate arrays, write a method to find the values that exist in both arrays and return them. ([Solution](https://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/)) +- Given an input array and another array that describes a new index for each element, mutate the input array so that each element ends up in their new index ([Solution](https://www.geeksforgeeks.org/reorder-a-array-according-to-given-indexes/)) + - Discuss the runtime of the algorithm and how you can be sure there would not be any infinite loops +- Given an array of non-negative numbers, find continuous subarray with sum to S. ([Solution 1](https://www.geeksforgeeks.org/find-subarray-with-given-sum/)) ([Solution 2](http://blog.gainlo.co/index.php/2016/06/01/subarray-with-given-sum/)) +- Given an array of numbers list out all triplets that sum to 0. Do so with a running time of less than O(n^3). ([Solution 1](https://www.geeksforgeeks.org/find-triplets-array-whose-sum-equal-zero/)) ([Solution 2](http://blog.gainlo.co/index.php/2016/07/19/3sum/)) +- Given an array of numbers list out all quadruplets that sum to 0. Do so with a running time of less than O(n^4). ([Solution](https://www.geeksforgeeks.org/find-four-numbers-with-sum-equal-to-given-sum/)) +- Given an array of integers, find the subarray with the largest sum. ([Solution](https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/)) +- Find the second maximum value in an array. ([Solution](https://www.geeksforgeeks.org/find-second-largest-element-array/)) +- Rotate an array by an offset of k. ([Solution](https://www.geeksforgeeks.org/array-rotation/)) +- Remove duplicates in an unsorted array where the duplicates are at a distance of k or less from each other. ([Solution](https://www.geeksforgeeks.org/check-given-array-contains-duplicate-elements-within-k-distance/)) +- Given an unsorted list of integers, return true if the list contains any duplicates within k indices of each element. Do it faster than O(n^2). ([Solution](https://www.geeksforgeeks.org/check-given-array-contains-duplicate-elements-within-k-distance/)) + - Given an unsorted list of integers, return true if the list contains any fuzzy duplicates within k indices of each element. A fuzzy duplicate is another integer within d of the original integer. Do it faster than O(n^2). - E.g. If d = 4, then 6 is a fuzzy duplicate of 3 but 8 is not. -- Say you have an unordered list of numbers ranging from 1 to n, and one of the numbers is removed, how do you find that number? What if two numbers are removed? -- Given an array of string, find the duplicated elements. - - [Source](http://blog.gainlo.co/index.php/2016/05/10/duplicate-elements-of-an-array/). -- Given an array of integers, find a maximum sum of non-adjacent elements. +- Say you have an unordered list of numbers ranging from 1 to n, and one of the numbers is removed, how do you find that number? What if two numbers are removed? ([Solution](https://www.geeksforgeeks.org/find-the-missing-number/)) +- Given an array of string, find the duplicated elements. ([Solution 1](https://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/)) ([Solution 2](http://blog.gainlo.co/index.php/2016/05/10/duplicate-elements-of-an-array/)) +- Given an array of integers, find a maximum sum of non-adjacent elements. ([Solution 1](https://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/)) ([Solution 2](http://blog.gainlo.co/index.php/2016/12/02/uber-interview-question-maximum-sum-non-adjacent-elements/)) - E.g. `[1, 0, 3, 9, 2]` should return `10 (1 + 9)`. - - [Source](http://blog.gainlo.co/index.php/2016/12/02/uber-interview-question-maximum-sum-non-adjacent-elements/) -- Given an array of integers, modify the array by moving all the zeroes to the end (right side). The order of other elements doesn't matter. +- Given an array of integers, modify the array by moving all the zeroes to the end (right side). The order of other elements doesn't matter. ([Solution 1](https://www.geeksforgeeks.org/move-zeroes-end-array/)) ([Solution 2](http://blog.gainlo.co/index.php/2016/11/18/uber-interview-question-move-zeroes/)) - E.g. `[1, 2, 0, 3, 0, 1, 2]`, the program can output `[1, 2, 3, 1, 2, 0, 0]`. - - [Source](http://blog.gainlo.co/index.php/2016/11/18/uber-interview-question-move-zeroes/). -- Given an array, return the length of the longest increasing contiguous subarray. - - E.g., `[1, 3, 2, 3, 4, 8, 7, 9]`, should return `4` because the longest increasing array is `[2, 3, 4, 8]`. - - [Source](http://blog.gainlo.co/index.php/2017/02/02/uber-interview-questions-longest-increasing-subarray/). -- Given an array of integers where every value appears twice except one, find the single, non-repeating value. Follow up: do so with O(1) space. +- Given an array, return the length of the longest increasing contiguous subarray. ([Solution 1](https://www.geeksforgeeks.org/longest-increasing-subarray/)) ([Solution 2](http://blog.gainlo.co/index.php/2017/02/02/uber-interview-questions-longest-increasing-subarray/)) + - E.g., `[1, 3, 2, 3, 4, 8, 7, 9]`, should return `4` because the longest increasing array is `[2, 3, 4, 8]` +- Given an array of integers where every value appears twice except one, find the single, non-repeating value. Follow up: do so with O(1) space. ([Solution](https://www.geeksforgeeks.org/find-element-appears-array-every-element-appears-twice/)) - E.g., `[2, 5, 3, 2, 1, 3, 4, 5, 1]` returns 4, because it is the only value that appears in the array only once. + +#### Other +- In an array of arrays, e.g. given `[[], [1, 2, 3], [4, 5], [], [], [6, 7], [8], [9, 10], [], []]`, print: `1, 2, 3, 4, 5, 6, 7, 8, 9, 10`. + - Implement an iterator that supports `hasNext()`, `next()` and `remove()` methods. +- Paginate an array with constraints, such as skipping certain items. +- Given array of arrays, sort them in ascending order. +- Given an array containing only digits `0-9`, add one to the number and return the array. + - E.g. Given `[1, 4, 2, 1]` which represents `1421`, return `[1, 4, 2, 2]` which represents `1422`. diff --git a/domain/security.md b/domain/security.md index 1c5216ae..da4312b1 100644 --- a/domain/security.md +++ b/domain/security.md @@ -5,7 +5,7 @@ Security #### Symmetrical Encryption -- Symmetrical encryption is a type of encryption where one key can be used to encrypt messages and also decrypt the same message. +- Symmetrical encryption is a type of encryption where the same key is used to encrypt plaintext messages and to decrypt ciphertext. - Symmetrical encryption is usually much less computationally expensive as compared to asymmetric encryption. - Often called "shared secret" encryption, or "secret key" encryption. - To use a symmetric encryption scheme, the sender and receiver must securely share a key in advance. This sharing can be done via asymmetric encryption. @@ -13,8 +13,8 @@ Security #### Asymmetric Encryption - A pair of keys are required: a **private key** and a **public key**. Public keys can be shared with anyone while private keys should be kept secret and known only to the owner. -- A private key can be used to decrypt a message encrypted by a public key. A successful decryption verifies that the holder possesses the private key. -- Also known as public key cryptography. +- A private key can be used to decrypt a message encrypted by the corresponding public key. A successful decryption verifies that the holder possesses the private key. +- Also known as public-key cryptography. ## Public Key Infrastructure @@ -30,7 +30,7 @@ An SSH session consists of two stages, **Negotiating Encryption** and **User Aut #### Negotiating Encryption -The goal of this stage is for the client and server to agree upon and establish encryption to protect future communication, by generating an identical session key. One possible algorithm to generate the key is the Diffie–Hellman key exchange scheme. Each party generates a public/private key pair and exchanges the public key. After obtaining an authentic copy of each other's public keys, each party can compute a shared secret offline. +The goal of this stage is for the client and server to agree upon and establish encryption to protect future communication, by generating an identical session key. One possible algorithm to generate the session key is the Diffie–Hellman key exchange scheme. Each party generates a public/private key pair and exchanges the public key. After obtaining an authentic copy of each other's public keys, each party can compute a shared secret offline. The basis of this procedure for classic Diffie-Hellman is: diff --git a/interviewers/basics.md b/interviewers/basics.md index a803e1b6..6ab54c14 100644 --- a/interviewers/basics.md +++ b/interviewers/basics.md @@ -16,5 +16,5 @@ These items will all change based on your specific company and needs but these i ## Tech Question Technique - **Tools** - Using a text editor such as Sublime or Atom will give the interviewee syntax highlighting but doesn't show compiler errors which can be a help. -- **Nitpicking** - Sometimes psuedocode is okay. If testing in C# do you really need the interviewee to write `Console.WriteLine()` or is `Print()` good enough? --**Keep Dialog Open** - Don't leave the interviewee alone or sit quietly by as they attempt to coe. Give some subtle hints like "I see you're doing ____, can you think of any other ways to accomplish this?" It's unlikely that the interviewee will be working in a silo should they get the job, is there any reason they should be during the interview? +- **Nitpicking** - Sometimes pseudocode is okay. If testing in C# do you really need the interviewee to write `Console.WriteLine()` or is `Print()` good enough? +-**Keep Dialog Open** - Don't leave the interviewee alone or sit quietly by as they attempt to code. Give some subtle hints like "I see you're doing ____, can you think of any other ways to accomplish this?" It's unlikely that the interviewee will be working in a silo should they get the job, is there any reason they should be during the interview? diff --git a/non-technical/behavioral.md b/non-technical/behavioral.md index 1ae38c6f..9895bc49 100644 --- a/non-technical/behavioral.md +++ b/non-technical/behavioral.md @@ -91,7 +91,6 @@ Source: [Glassdoor](https://hired.com/blog/candidates/10-top-interview-questions - Why are you interested in this opportunity? - What are your salary expectations? - Why are you looking to leave your current company? -- What is your biggest strength and area of growth? - Tell me about a time your work responsibilities got a little overwhelming. What did you do? - Give me an example of a time when you had a difference of opinion with a team member. How did you handle that? - Tell me about a challenge you faced recently in your role. How did you tackle it? What was the outcome? diff --git a/preparing/README.md b/preparing/README.md index 38bcd79f..9f24d6f7 100644 --- a/preparing/README.md +++ b/preparing/README.md @@ -3,15 +3,15 @@ Preparing for a Coding Interview ### Picking a Programming Language -Before anything else, you need to pick a programming language to do your interviews in. Most companies will let you code in any language you want, the only exception I know being Google, where they only allow candidates to pick from Java, C++ or Python for their algorithmic coding interviews. Most of the time, I would recommend that you use a language that you are extremely familiar with rather than picking up a new language just for doing interviews because the company uses that language heavily. +Before anything else, you need to pick a programming language to do your interviews in. Most companies will let you code in any language you want, the only exception I know being Google, where they only allow candidates to pick from Java, C++, JavaScript or Python for their algorithmic coding interviews. Most of the time, I would recommend that you use a language that you are extremely familiar with rather than picking up a new language just for doing interviews because the company uses that language heavily. -There are some languages which are more suitable than others for coding interviews and some languages you absolutely want to avoid. From my experience interviewing as an interviewer, most candidates pick Python or Java. Other commonly seen languages include JavaScript, Ruby and C++. I would absolutely avoid lower level languages like C or Go, simply because they lack in many standard library functions and data structures. +There are some languages which are more suitable than others for coding interviews and some languages you absolutely want to avoid. From my experience as an interviewer, most candidates pick Python or Java. Other commonly seen languages include JavaScript, Ruby and C++. I would absolutely avoid lower level languages like C or Go, simply because they lack many standard library functions and data structures. -Personally, Python is my de facto choice for coding algorithms during interviews because it is succinct and has a pretty huge library of functions and data structures available. One of my top reasons for recommending Python is that it uses consistent APIs that operate on different data structures, such as `len()`, `for ... in ...` and slicing notation on sequences (strings/lists/tuples). Getting the last element in a sequence is `arr[-1]` and reversing it is simply `arr[::-1]`. You can achieve a lot with minimal syntax in Python. +Personally, Python is my de facto choice for algorithm coding interviews because it is succinct and has a pretty huge library of functions and data structures available. One of my top reasons for recommending Python is that it uses consistent APIs that operate on different data structures, such as `len()`, `for ... in ...` and slicing notation on sequences (strings/lists/tuples). Getting the last element in a sequence is `arr[-1]` and reversing it is simply `arr[::-1]`. You can achieve a lot with minimal syntax in Python. -Java is a decent choice too but having to constantly declare types in your code means extra keystrokes which results in slower coding/typing speed. This issue will be more apparent when you have to write on a whiteboard during on-site interviews. The reasons for choosing/not choosing C++ are similar to Java. Ultimately, Python, Java and C++ are decent choices of languages. If you have been using Java at work for a while now and do not have time to be comfortably familiar with another language, I would recommend just sticking to Java instead of picking up Python from scratch just for interviews to avoid having to context switch between languages during work vs interviews. Most of the time, the bottleneck is in the thinking and not the writing. +Java is a decent choice too but having to constantly declare types in your code means extra keystrokes which results in slower coding/typing speed. This issue will be more apparent when you have to write on a whiteboard during on-site interviews. The reasons for choosing/not choosing C++ are similar to Java. Ultimately, Python, Java and C++ are decent choices of languages. If you have been using Java at work for a while now and do not have time to be comfortably familiar with another language, I would recommend just sticking to Java instead of picking up Python from scratch just for the sake of interviews. Doing so, you can avoid having to context switch between languages during work vs interviews. Most of the time, the bottleneck is in the thinking and not the writing. It takes some getting used to before one becomes fluent in a language and be able to wield it with ease. -One exception to the convention of allowing you to "pick any programming language you want" is when you are interviewing for a domain-specific position, such as Front End/iOS/Android Engineer roles, in which you would need to be familiar with coding algorithms in JavaScript, Objective-C/Swift and Java respectively. If you need to use a data structure that the language does not support, such as a Queue or Heap in JavaScript, perhaps try asking the interviewer whether you can assume that you have a data structure that implements certain methods with specified time complexities. If the implementation of that data structure is not crucial to solving the problem, the interviewer will usually allow it. In reality, being aware of existing data structures and selecting the appropriate ones to tackle the problem at hand is more important than knowing the intricate implementation details. +One exception to the convention of allowing you to "pick any programming language you want" is when you are interviewing for a domain-specific position, such as Front End/iOS/Android Engineer roles, in which you would need to be familiar with coding in JavaScript, Objective-C/Swift and Java respectively. If you need to use a data structure that the language does not support, such as a Queue or Heap in JavaScript, perhaps try asking the interviewer whether you can assume that you have a data structure that implements certain methods with specified time complexities. If the implementation of that data structure is not crucial to solving the problem, the interviewer will usually allow this. In reality, being aware of existing data structures and selecting the appropriate ones to tackle the problem at hand is more important than knowing the intricate implementation details. ### Review your CS101 @@ -27,11 +27,11 @@ If you are interested in how data structures are implemented, check out [Lago](h Next, gain familiarity and mastery of the algorithms and data structures in your chosen programming language: -1. Practice coding algorithms using your chosen language. While [Cracking the Coding Interview](http://www.crackingthecodinginterview.com/) is a good resource for practice, I prefer being able to type code, run it and get instant feedback. There are various Online Judges such as [LeetCode](https://leetcode.com/), [HackerRank](https://www.hackerrank.com/) and [CodeForces](http://codeforces.com/) for you to practice questions online and get used to the language. From experience, LeetCode questions are the most similar to the kind of questions being asked in interviews whereas HackerRank and CodeForces questions are more similar to competitive programming questions. If you practice enough LeetCode questions, there is a good chance that you would have seen/done your actual interview question (or some variant) on LeetCode before. If you are more of a visual person, [Coderust](https://www.educative.io/collection/5642554087309312/5679846214598656) explains the common algorithm questions through step-by-step visualizations which makes understanding the solutions much easier. -2. Learn and understand the time and space complexities of the common operations in your chosen language. For Python, this [page](https://wiki.python.org/moin/TimeComplexity) will come in handy. Also find out the underlying sorting algorithm that is being used in the language's `sort()` function and its time and space complexity (in Python its Timsort which is a hybrid sort). After completing a question on LeetCode, I usually add the time and space complexities of the written code as comments above the function body to remind myself to analyze the algorithm after I am done with the implementation. -3. Read up on the recommended coding style for your language and stick to it. If you have chosen Python, refer to the PEP 8 Style Guide. If you have chosen Java, refer to Google's Java Style Guide. -4. Find out and be familiar with the common pitfalls and caveats of the language. If you point out them out during the interview and intelligently avoid falling into them, you will usually impress the interviewer and that results in bonus points in your feedback, regardless of whether the interviewer is familiar with the language or not. -5. Gain a broad exposure to questions from various topics. In the second half of the article I mention algorithm topics and practice questions for each topic. Do around 100–200 LeetCode questions and you should be good. +1. Practice coding algorithms using your chosen language. While [Cracking the Coding Interview](http://www.crackingthecodinginterview.com/) is a good resource for practice, I prefer being able to type code, run it and get instant feedback. There are various Online Judges such as [LeetCode](https://leetcode.com/), [HackerRank](https://www.hackerrank.com/) and [CodeForces](http://codeforces.com/) for you to practice questions online and get used to the language. From experience, LeetCode questions are the most similar to the kind of questions being asked in interviews whereas HackerRank and CodeForces questions resemble competitive programming questions. If you practice enough LeetCode questions, there is a good chance that you would have seen/done your actual interview question (or some variant) on LeetCode before. If you are more of a visual person, [Coderust](https://www.educative.io/collection/5642554087309312/5679846214598656) explains the common algorithm questions through step-by-step visualizations which makes understanding the solutions much easier. +1. Learn and understand the time and space complexities of the common operations in your chosen language. For Python, this [page](https://wiki.python.org/moin/TimeComplexity) will come in handy. Also find out the underlying sorting algorithm that is being used in the language's `sort()` function and its time and space complexity (in Python its Timsort which is a hybrid sort). After completing a question on LeetCode, I usually add the time and space complexities of the written code as comments above the function body to remind myself to analyze the algorithm after I am done with the implementation. +1. Read up on the recommended coding style for your language and stick to it. If you have chosen Python, refer to the PEP 8 Style Guide. If you have chosen Java, refer to Google's Java Style Guide. +1. Find out and be familiar with the common pitfalls and caveats of the language. If you point them out during the interview and intelligently avoid falling into them, you will usually impress the interviewer and that results in bonus points for your feedback, regardless of whether the interviewer is familiar with the language or not. +1. Gain a broad exposure to questions from various topics. In the second half of the article I mention algorithm topics and practice questions for each topic. Do around 100–200 LeetCode questions and you should be good. Practice, practice and more practice! @@ -49,34 +49,55 @@ Use earphones and make sure you are in a quiet environment. You definitely do no **Self Introduction** -TODO +Prepare a self introduction that follows the following outline (inspired by "Cracking the Coding Interview" by Gayle McDowell): + +1. A sentence about your current or most recent role. +1. A few sentences about your (academic) background. What did you focus on? +1. Some sentences about your professional experience after school/university. Where did you work? What projects did you deal with? What where typical challenges and tasks? Which technologies did you use? +1. Mention one to two sentences about what you do outside of work, if it is relevant for the role. +1. Finish with a statement saying why you are seeking a new job opportunity and why you are interested in the role you applied for. + +An example of the above could be: + +> I'm John Doe and currently a Software Engineer at Google. +> +> My background is in Computer Science, where I received my bachelor's degree at MIT and my Master's degree at Stanford. I mainly did research on how to decrease complexity of search algorithms. +> +> After university, I started to work at Microsoft as a Software Engineer. It was a great experience as I was working in the Office team contributing to MS Word and MS Powerpoint. I learned a lot about C# and .NET back then. After about two years, I got an offer from Google where I have been working since then. I'm now leading the Search Optimization team and have gained a lot of knowledge in scalability and domain knowledge. My daily tasks consist of optimizing search queries and mentoring junior engineers. +> +> Outside of work I develop a on open source projects written in Python. Examples of some open source projects I created are . +> +> I'm now seeking new job opportunities in the Boston area since I'm relocating for personal reasons. In particular I think Boston Dynamics is a perfect fit for my interests as well as my skill set. **Upon Getting the Question** -Many candidates jump into coding the moment they hear the question. That is usually a big mistake. Take a moment to repeat the question back at the interviewer and make sure that you understand exactly what they are asking. If you misunderstood and when you repeat back the question, they will clarify. +Many candidates jump into coding the moment they hear the question. That is usually a big mistake. Take a moment to repeat the question back at the interviewer and make sure that you understand exactly what they are asking. Repeating back/rephrasing the question will reduce chances of miscommunication. + +Always seek clarification about the question upon hearing it even if it you think it is clear to you. You might discover something that you have missed out and it also sends a signal to the interviewer that you are a careful person who pays attention to details. Some interviewers deliberately omit important details to see if you ask the right questions. -Always seek clarification about the question upon hearing it even if it you think it is clear to you. You might discover something that you have missed out and it also sends a signal to the interviewer that you are a careful person who pays attention to details. Some interviewers deliberately omit important details to see if you ask the right questions. Consider asking the following questions: +Some common questions you can ask: - How big is the size of the input? - How big is the range of values? - What kind of values are there? Are there negative numbers? Floating points? Will there be empty inputs? - Are there duplicates within the input? - What are some extreme cases of the input? +- Can I destroy the original array/graph/data structure? - How is the input stored? If you are given a dictionary of words, is it a list of strings or a Trie? After you have sufficiently clarified the scope and intention of the problem, explain your high level approach to the interviewer even if it is a naive solution. If you are stuck, consider various approaches and explain out loud why it will/will not work. Sometimes your interviewer might drop hints and lead you towards the right path. Start with a brute force approach, communicate it to the interviewer, explain the time and space complexity and why it is bad. It is unlikely that the brute force approach will be one that you will be coding. At this point, the interviewer will usually pop the dreaded "Can we do better?" question, meaning that they are looking for a more optimal approach. In my opinion, this is usually the hardest part of the interview. In general, look for repeated work and try to optimize them by potentially caching the calculated result somewhere and reference it later, rather than having to compute it all over again. There are some tips on tackling topic-specific questions that I dive into details below. -Only start coding after you and your interviewer have agreed on an approach and has given you the green light. +Only start coding after you and your interviewer have agreed on an approach and they have given you the green light. **Starting to Code** -Write your code with good coding style. Reading code written by others is usually not an enjoyable task. Reading horribly-formatted code by others makes it worse. Your goal is to make your interviewer understand the code you have written so that they can quickly evaluate if your code does what you say it does and whether it solves the given problem. Use clear variable names, avoid single letter names unless they are for iteration. However, if you are coding on a whiteboard, you might not want to use extremely verbose variable names for the sake of reducing the amount you have to write. +Write your code with good coding style. Reading code written by others is usually not an enjoyable task. Reading horribly-formatted code by others makes it worse. Your goal is to make your interviewer understand the code you have written so that they can quickly evaluate if your code does what you say it does and whether it solves the given problem. Use clear variable names, avoid single letter names unless they are for iteration. However, if you are coding on a whiteboard, you might not want to use extremely verbose variable names for the sake of reducing the amount you have to write. Abbreviations are usually fine if you explain what it means beforehand. Always be explaining what you are currently writing/typing to the interviewer. This is not about literally reading out what you are typing to the interviewer. Talk about the section of the code you are currently implementing at a higher level, explain why it is written as such and what it is trying to achieve. -When you copy and paste code, consider whether it is necessary. Sometimes it is, sometimes it is not. If you find yourself copying and pasting one large chunk of code spanning multiple lines, it is probably an indicator that you can refactor by containing those lines into a function. If it is just a single line you copied, usually it is fine. Do remember to change the respective variables in your copied line of code where relevant. Copy-paste errors are a common source of bugs even in day-to-day coding! +While coding, if you find yourself copying and pasting code, consider whether it is necessary. If you find yourself copying and pasting one large chunk of code spanning multiple lines, it is usually an indicator that you can refactor by extracting those lines into a function and defining parameters for the differences in them. If it is just a single line you copied, usually it is fine. Do remember to change the respective variables in your copied line of code where relevant. Copy-paste errors are a common source of bugs even in day-to-day coding! **After Coding** @@ -84,13 +105,13 @@ After you have finished coding, do not immediately announce to the interviewer t Firstly, look through your code from start to finish as if it is the first time you are seeing it, as if it was written by someone else and you are trying to spot bugs in it. That's exactly what your interviewer will be doing. Look through and fix any minor issues you may find. -Next, come up with small test cases and step through the code (not your algorithm!) with those sample input. Interviewers like it when you read their mind and what they usually do after you have finished coding would be to get you to write tests. It is a huge plus if you write tests for your code even before prompts from them. You should be emulating a debugger when stepping through and jot down or say out the values of certain variables as you step through the lines of code. +Next, come up with small test cases and step through the code (not your algorithm!) with those sample input. What interviewers usually do after you have finished coding would be to get you to write tests. It is a huge plus if you write tests for your code even before they prompt you to do so. You should be emulating a debugger when stepping through and jot down or say out the values of the important variables as you step through the lines of code. If there are huge duplicated chunks of code in your solution, it would be a good chance to refactor it and demonstrate to the interviewer that you are one who values code quality. Also look out for places where you can do [short-circuit evaluation](https://en.wikipedia.org/wiki/Short-circuit_evaluation). Lastly, give the time/space complexity of your code and explain why it is such. You can even annotate certain chunks of your code with the various time/space complexities to demonstrate your understanding of your code and the APIs of your chosen programming language. Explain any trade-offs in your current approach vs alternative approaches, possibly in terms of time/space. -If your interviewer is happy with the solution, the interview usually ends here. It is also not uncommon that the interviewer asks you extension questions, such as how you would handle the problem if the whole input is too large to fit into memory, or if the input arrives as a stream. This is a common follow-up question at Google where they care a lot about scale. The answer is usually a divide-and-conquer approach — perform distributed processing of the data and only read certain chunks of the input from disk into memory, write the output back to disk and combine them later on. +If your interviewer is happy with the solution, the interview usually ends here. It is also not uncommon that the interviewer asks you extension questions, such as how you would handle the problem if the whole input is too large to fit into memory, or if the input arrives as a stream. This is a common follow-up question at Google where they care a lot about scale. The answer is usually a divide-and-conquer approach — perform distributed processing of the data and only read certain chunks of the input from disk into memory, write the output back to disk, and combine them later on. ### Practicing via Mock Interviews