DEV Community

Cover image for 4+ years of cracking technical interviews
Aditya Tyagi
Aditya Tyagi

Posted on • Originally published at adityatyagi.com

4+ years of cracking technical interviews

A framework to solve any technical interview question

I have been working as a Senior Software Engineer — II (Frontend) from quite some time now and have been on both sides of the interview table. I have given a lot of technical interviews and have taken the same amount (if not more).

From white-boarding the data structures and algorithmic questions to pair-programming with my interviewer, its been an eye-opening & humbling experience of how draining these interviews can get!

Therefore, over these last 4 years, I have come up with this little framework that has helped me crack multiple roles in various tech companies.

There are 5 major parts to this problem solving approach

  1. Understand the problem
  2. Explore concrete examples
  3. Break it down
  4. Solve or Simplify
  5. Look back and refactor

Let’s go through each one of them in detail:

Understand The Problem

As soon as you are given the question, do not start slapping the keyboard and declaring variables. Breathe. Read the question and then re-read it.

“It is foolish to answer a question that you do not understand.”

- “How to Solve it” by George Polya

Then, try to note down answers to the following questions:

  1. Can I restate the problem in my own words?
  2. What are the inputs that go into the problem? This is the place where you can ask the interviewer for the edge cases with respect to inputs.
  3. What are the outputs that should come from the solution to the problem?
  4. Can the outputs be determined from the inputs? In other words, do I have enough information to solve the problem?
  5. How should I label the important pieces of data (variables declaration) that are part of the problem?

Explore Concrete Examples

Coming up with examples can help you understand the problem better. These examples also provide sanity checks that your solution works the way it should work.

This can help you to understand the nature of inputs and outputs more clearly and reveal any corner/edge cases.

These are nothing but user stories or unit tests for the problem statements.

For example, consider this question:

Write a function charCount which takes a string and returns count of each character in the string?

The examples of this can be:

charCount("aaa");        // Output -> {a:3}
charCount("hello");      // Output -> {h:1, e: 1, l: 2, o: 1}

// Check examples for empty inputs
charCount(""); // Output -> { }

// Check examples for invalid inputs
charCount(1234);         // Output -> { } 

// Check examples for invalid inputs
charCount(false);        // Output -> { }
Enter fullscreen mode Exit fullscreen mode

Break It Down

This is one of the most important, yet most ignored/skipped step. You need to keep the interviewer on the same page throughout your problem solving journey.

  1. Communicate while breaking the problem down
  2. Ask questions like “Does this sound good?” or “Am I going the right path?”
  3. Write comments and not the actual code.
  4. Explicitly write out the steps you need to take. You need to just write the pseudo-code or steps that you will be taking to solve the problem.

The process of breaking down the problem compels you to think about the code you will write before you write it and helps you catch any lingering conceptual issues or misunderstandings. This is an important step to follow and will help you immensely before you dive in and have to worry about the details like syntax of the code.

Solve or Simplify

By the time you arrive at this step, you should already have the pseudo-code written. All you have to do is just write the code now.

Defeat Them in Detail: The Divide and Conquer Strategy.

Look at the parts and determine how to control the individual parts, create dissension and leverage it.

- Robert Greene

If you are “stuck” and are not able to proceed, do not worry. Try to break down the problem into smaller problems. Try to identify a simpler problem and then solve it. This will also give you a psychological sense of achievement and thus help you proceed with the problem “emotionally”.

Yes, emotionally. There have been times when I started sweating, mouth went dry while solving a DSA question. One has to be in a balanced mental state to come down to a solution as this is a mental game!

To simplify:

  1. Find the core difficulty in what you are trying to do
  2. Temporarily ignore the difficulty
  3. Write a simplified solution
  4. Then incorporate that difficulty back in

Look Back And Refactor

This is the last piece, but the piece of this framework that will distinguish between a great candidate from a good one!

For refactoring, ask yourself:

  1. Can I check the result?
  2. Can I derive the result differently?
  3. Can I understand the solution at a glance? Is the solution readable?
  4. Can I use the same method for some other problem?
  5. Can I improve the performance of the solution?
  6. Can I think of other ways to refactor?
  7. How have other people solved the same problem? This is something that comes in “Looking Back” area of the framework!

All the very best for your interview (if you have any coming up).


Thanks for reading ❤

If this blog was able to bring value, please follow me on Medium! Your support keeps me driven!

Originally published on adityatyagi.com

Want to connect?

Follow me on Twitter and LinkedIn or reach out in the comments below!

My name is Aditya. I am a Senior Software Engineer - II (Frontend). I blog about web development!

Discussion (4)

Collapse
maurice35 profile image
Maurice Kollewe T

Great steps! Aditya, thanks for sharing.

Collapse
adityatyagi profile image
Aditya Tyagi Author

Thanks!

Collapse
spsalsm profile image
Sean Salsman

Excellent! Thank you for this. I’ll keep these steps in mind the next time I’m faced with a tech interview.

Collapse
adityatyagi profile image
Aditya Tyagi Author

Thanks Sean!
All the very best!