What language should you use? All these questions and more are answered. How Questions are Selected It's All Relative Frequently Asked Questions Behind the Scenes Learn what happens behind the scenes during your interview, how decisions really get made, who you interview with, and what they ask you. Learn what your interviewers are looking for and how much code you need to know. This section describes what a software engineer's resume should look like and what you should be doing well before your interview.
Getting the Right Experience Building a Network Preparation Map Behavioral Preparation Although most of a software engineering interview will be technical, behavioral questions matter too. This section covers how to prepare for behavioral questions and how to give strong, structured responses.
Acing the Google Interview: The Ultimate Guide
In order to optimize your solution, you need to be able to discuss the efficiency of your algorithm. It also teaches you what exactly "good coding" is when it comes to an interview. Each section opens with a discussion of the core knowledge and strategies to tackle this type of question, diving into exactly how you break down and solve it. A link is provided with the book so that you can download, compile, and play with the solutions yourself.
Major revisions were done to almost every solution, including a number of alternate solutions added. The introductory chapters were massively expanded, as were the opening of each of the chapters under Technical Questions. In addition, 24 new questions were added. I wouldn't have blown a great job that I really wanted. This book goes beyond the usual answers to questions likely to be asked. A stack object is created at the point of its definition, and lives until the end of its scope basically, until the closing curly brace of the block it is declared in. A heap object is created with the new operator and lives until delete is called on it.
The problem with raw pointers is that ownership is not enforced; it is the responsibility of the programmer to ensure that the object pointed to is deleted, and deleted only once. Advanced candidates might also mention exception safety here, because the possibility of exceptions makes it significantly more complicated to ensure eventual deletion. Ask which ones can be used in standard containers e.
The former is more exception-safe when used as a function argument, and might also be implemented more efficiently. What is an iterator, and what different kinds do you know of? Explain how the begin and end iterators of a range correspond to its elements and illustrate this by giving the expressions for begin and end iterators of an array arr. As in any programming language, one of the most common tasks to perform on a container is to iterate over it. Asking the candidate about these will reveal how well they understand the concept of iterators, as well as the structure of the underlying container.
1. Be enthusiastic
An iterator resembles a smart pointer, in the sense that it points to a particular object in a container. But iterators have additional operations besides deferencing, depending on their type : forward iterators can be incremented, bidirectional iterators can additionally be decremented, and random access iterators can additionally be moved by an arbitrary offset.
There are also output iterators, which may for example add objects to the container when assigned to. By convention, the begin iterator of a collection refers to the first element, and the end iterator refers one past the last element. In other words, they form a half-open range: [begin, end.
by Daniel Tunkelang
Ask how the code could be fixed to sort an std::list e. You could even ask the candidate to implement an iterator for a particular data structure e. Give at least 3 examples of undefined behavior. Typically, such cases are to be avoided in practice, so this question is to test whether the interview candidate has seen practical examples of such code. Undefined behavior UB means that the standard guarantees nothing about how the program should behave.
Unspecified or implementation-defined behavior means that the standard requires the behavior to be well-defined, but leaves the definition up to the compiler implementation. This is only the textbook definition; candidates should mention that undefined behavior implies that anything might happen: the program works as intended, it crashes, it causes demons to fly out of your nose.
They should mention that UB should always be avoided. They might mention that implementation-defined behavior should probably be avoided as well. At what stage of compilation is the preprocessor invoked , and what kind of directives are there?
The following is the declaration of a macro that is used as a constant in some internal API header B is another entity :. List two issues with this macro: one related to this particular one, for which you should give illustrative example code that breaks the macro, and one related to all macros hint: think of names. The output of the preprocessor is passed to the compiler. Even junior candidates should give an answer along these lines.
Common preprocessor directives are include, define, ifdef, ifndef, if, else, elif, endif. Candidates should be able to list most of these. They might also mention less common directives, such as undef and pragma.
- Black & White World II!
- Top 100 Data Structure and Algorithm Interview Questions for Java Programmers.
- Mysore Style Cooking.
Good candidates will mention that this should probably not have been a macro in the first place, but simply a compile-time constant. Overly short names. Preprocessor macros are all in a single scope, which spans all files included afterwards as well, so one has to be very careful about name clashes.
Follow-up questions It is common for candidates to mention only one of the two pairs of missing parentheses. In this case, prompt them to find more issues.
Retiring a Great Interview Problem
Write a templated struct that determines, at compile time, whether its template argument T is a pointer. It could be implemented like this:. Template overload resolution will pick the most specific version, so if the type is a pointer, the last one will be selected, which contains an enum field value with the value true.
- Join the Toptal community..
- 100 Days of Real Food: How We Did It, What We Learned, and 100 Easy, Wholesome Recipes Your Family Will Love.
- An Introduction to Structural Analysis. The Network Approach to Social Research!
Otherwise it falls back to the first, where value is false. It is also possible to use a static const bool instead of an enum , but this has some drawbacks. It would work in some cases, but would fail if you take the address, for example. This is an advanced skill, useful when writing library code, for example to avoid incorrect or inefficient usage of the API.
C++ programming solved programs/examples
Do not punish the candidate for not knowing the exact usage of all these standard library templates. The important thing is that they grasp the overall concepts; the details can be looked up online easily enough. Describe what a max heap is. Provide the definition of a max heap class which supports a wide range of element types and all basic operations that can be performed on a heap. At first, this seems like a pure algorithms question, but note that we are not asking for the implementation of any of the operations. Depending on the design decisions that the interview candidate makes along the way, the result could be something like this:.
Many design decisions can be made along the way, each of which can be used by the interviewer as a hook to lead into further discussion about the various tradeoffs in the design.