A Comprehensive Guide to Solving Problems Technical Interviews Like a Pro

Mastering the Art of Problem Solving in Coding Interviews: A Comprehensive Guide

Solving coding problems is essential for any engineer, whether you're applying for a new job or just trying to improve your skills. But how do you approach a coding problem? Here's a step-by-step guide to help you solve any coding problem:

P - PROBLEM

The first step is not to jump into code but to read and understand the problem. Begin by summarizing the key points of the problem. Make sure you have a clear understanding of what the problem is asking you to do.

Q - QUESTIONS

Next, ask questions Ask clarifying questions to ensure you have a complete understanding of the problem. For a function, verify inputs and outputs types and constraints. Here are some example questions:

  • Is the dataset sorted?
  • are there repeating elements in the dataset?
  • what are the possible input values for the function parameters?
  • does the data have negative values?

Once you understand the inputs and outputs, you can think better about solutions.

BFS - BRUTE FORCE SOLUTION

Don't be afraid or ashamed to offer up the first solution that comes to mind. The majority of the time, this solution is not ideal and will require some fine-tuning.

O - OPTIMIZE SOLUTION

Once you have a BFS, with your understanding of Data Structure and Algorithms, explain why your BFS is not an optimum solution. This helps you to understand the problem better and to come up with better solutions. Next, think out loud as you make your way to your better solution, verifying from your interviewer what is most important: memory or time.

Some helpful tips to improve your BFS:

  • use hash maps or tables to improve time complexity at the cost of space complexity.
  • try sorting the values in the dataset. It might make the dataset easier to work with.
  • a binary tree is best for sorted arrays.

For a better understanding of space and time complexity, check out this post

Write pseudocode step by step with comments where needed, making up function names where you can't remember a language-specific function/method. Once you have an optimized solution, test it with examples, at least one passing and failing case.

C - CODE

Now, you can write your code. Write code with readable variable names, focusing on the part of the algorithm that will make you stand out from the competition. Do not be scared to ask if you can use your favourite programming language.

T - TEST

After writing, it is time to test it. Test your code with various inputs, safeguarding your solution from false inputs and edge cases. Check for no parameters, 0, undefined, null, empty string, empty array, massive array, repetitions, nested loops, recursion, etc.

R - REVIEW

Once you're done and ready to submit your solution, review your submission with your interviewer, asking for feedback on readability and improvement. Here's a tricky one: ask the interviewer about the most intriguing solution they have seen to this problem.

Remember to communicate your thought process as much as possible, and don't be in a hurry. Follow the interviewer's advice, tips, and hints when given.

If you have a follow-up question about how to handle input too large for memory or an input that is a stream. The answer is to use a divide-and-conquer approach, where the input is divided into chunks, and each is processed and then combined to give the results.

Solving coding problems takes practice, but with the right approach, you can improve your skills and become a better programmer. Watch this [Google Interview video](youtube.com/watch?v=XKu_SEDAykw] for more tips and advice on how to solve coding problems.