A Recipe for Problem Solving

Fatima JannetFatima Jannet
3 min read

In this blog, I'll show you problem-solving steps that are helpful during the interview process or when you face a tough challenge. Let's start!

Step 1: Understand the problem

Many people learn coding, but the biggest challenge is problem-solving. Anyone can learn syntax and write code by copying or following steps. However, problem-solving skills are crucial and come with practice.

Imagine you are in an interview and asked a question you've never seen before. Don't panic; understand the question first. Many start coding right away, but writing lots of code doesn't help. Instead, ask questions to clarify the problem. Helpful questions include:

  1. Can we restate the problem in our own words?

  2. What are the inputs for the problem?

  3. What are the outputs of the problem?

  4. Can the outputs be determined from the inputs? In other words, do we have enough information to solve this problem?

  5. What should I label the important pieces of data that are part of the problem?

These question will help you to clear questions.

Step 2: Examples

  1. Start with simple examples

  2. Progress to more complex examples

  3. Explore example with empty

  4. Explore the example with invalid inputs

Explore if your code is able to perform this or not.

Step 3: Break it down

Write down the steps you need to take. They don't have to be valid code or follow syntax rules. Just outline the flowchart you plan to use. This will serve as a guide and help clarify your concepts. Essentially, create a layout, highlight the problems, and you'll be ready to go.

Step 4: Solve or Simplify

Solve the problem if you cannot ... Simplify the problem.

To simplify, follow these steps:

  1. Find the core difficulty

  2. Temporarily ignore that difficulty

  3. Write a simplified solution

  4. Then incorporate that difficulty.

Now, by doing this, we have already completed 90% of the challenge. If you reach this stage in the interview process, you can ask the interviewer for some suggestions. There's nothing wrong with this. If you solve 90% of a challenge, it demonstrates a lot about your problem-solving ability.

Step 5: Look back and Refactor

When it comes to interview, it's really important to ask these questions when you have finished solving the problem.

  1. Can we check the result?

    This one is obvious. We need to be sure that our code works.

  2. Can we drive the result differently?

    This is referring to the fact that there is rarely one solution to a problem

  3. Can we understand it at a glance? Can we use the result or method for some other problem?

    How easy is your solution to understand? Does it make sense when you see it on paper, a whiteboard, or in your code editor? When you write down a solution, take a moment to ask yourself if it resembles other solutions you have seen before. It develops a sense for solving other problems.

  4. Can you improve the performance of your solution?

    Here you need to be worry about time and space complexities. For example avoid a bunch of nested loops.

  5. How other people solve this problem?

    It can improve yourself, maybe even for the next interview.

These are the questions you should ask yourself.

10
Subscribe to my newsletter

Read articles from Fatima Jannet directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Fatima Jannet
Fatima Jannet