Google Interview approach

Clarifications and edge cases

  • How to handle nulls?

  • Will the input data fit in memory?

  • What kind of data will be provided?

    • For example, if we are talking about Trees, the nodes could contain any data type, like numbers, strings or objects. We need to clarify with the interviewer.

  • What is the size of the data?

  • Ask for sample input and output

Interfaces

Before we even try to solve the problem, the interfaces should be discussed. What it means is the method signatures should be defined. If we are going to have multiple functions, a proper naming convention for the methods should be provided and also give what kind of input data it will be taking in and the type of output.

This will keep the interviewer understand what we are trying to do.

Identifying one or more solutions

THINK OUT LOUD

You can start off with the first solution that comes to your mind, even the brute force ones. But keep talking out loud.

NO CODE YET

Then start talking about the approach you are gonna take. Discuss trade-offs as much as possible at every step. You need to discuss the time and space complexity.

Coding

Whatever the algorithm that you have discussed, put it into code form.

If possible, you can add comments to your code, but if you are communicating your approach to the interviewer, the comments can be ignored. It's just good to have.

If the number of lines of code is around 50, but the solution

Extra brownie points. If we write simple modular code with good naming conventions

It is okay if you forget about the signature of an inbuilt library function. You can explain to the interviewer what it will do, and you can proceed, or you can give your own implementation to it.

Verify

Dry run through the examples you have discussed in the clarifications.

Run unit tests

Last updated

Was this helpful?