🔥 Burn Fat Fast. Discover How! 💪

General tips Always validate input first. Check for inputs th | Coding interview preparation

General tips

Always validate input first. Check for inputs that are invalid, empty, negative, or different. Never assume you are given the valid parameters. Alternatively, clarify with the interviewer whether you can assume valid input (usually yes), which can save you time from writing code that does input validation.

Are there any time and space complexities requirements or constraints?

Check for off-by-one errors.

In languages where there are no automatic type coercion, check that concatenation of values are of the same type: int,str, and list.

After you finish your code, use a few example inputs to test your solution.

Is the algorithm supposed to run multiple times, perhaps on a web server? If yes, the input can likely be pre-processed to improve the efficiency in each API call.

Use a mix of functional and imperative programming paradigms:

Write pure functions as often as possible.
Use pure functions because they are easier to reason with and can help reduce bugs in your implementation.
Avoid mutating the parameters passed into your function, especially if they are passed by reference, unless you are sure of what you are doing.
Achieve a balance between accuracy and efficiency. Use the right amount of functional and imperative code where appropriate. Functional programming is usually expensive in terms of space complexity because of non-mutation and the repeated allocation of new objects. On the other hand, imperative code is faster because you operate on existing objects.
Avoid relying on mutating global variables. Global variables introduce state.
Make sure that you do not accidentally mutate global variables, especially if you have to rely on them.