# Solving coding chalenges

## A bit of History

In 1945 Hungarian mathematician George Pólya, described famous method of problem-solving:

1. First, we have to understand the problem
2. After understanding make a plan
3. Carry out the plan.
4. Look back on your work. How could it be done better?

This may sound a bit abstract, so let's translate this method into more concrete steps.

## Problem-solving strategy

### Understand the problem

1. Can I rephrase problem using your my own words?
2. What are the inputs?
3. What are the outputs?
4. How should I name the important pieces of data that are a part of the problem?
5. Explore concrete examples
2. Explore empty inputs
3. Explore invalid inputs

### Break it down

Write exact, atomic steps we need to take to solve the problem. They can be written on a piece of paper or as comments in the file containing code.

This forces you to think about the code you'll write before you write it and helps you catch any issues or misunderstandings before you dive into details (e.g. language syntax).

### Solve the problem

Now when you have to concede defined steps solving the problem should be much easier. However, if you struggle to get back to previous steps to make sure that you have a good understanding of the problem and you know exactly what to do. You can also try a few alternative approaches such as solving a similar problem or solve a simplified version of the current problem by temporally excluding the most difficult part.

### Refactor & Simplify

1. Try to refactor the code
2. Improve performance (Big-O notation)
3. Check how other people solved this problem

This strategy is inspired by Colt Steele.

## Deliberate practice

Deliberate (Kata) practice is a great supplement of the above strategy. It involves attention, reworks and leads to new knowledge and skills that can later be developed into more complex knowledge and stronger skills.

Let's take a look at the concrete application of this:

1. Solve a coding puzzle
2. Compare your solution with the solution with this repository (or other solution on the internet)
3. Think about how both solutions differ and what can be improved.
4. Solve coding puzzle again (without looking at the ordinal solution) and compare...

Perform above steps multiple times over a period of few days/weeks/months. Bit by bit your mind will rewire itself, you will have a better understanding of the problem/context and code challenge will simply feel familiar to you over time. Do it until solving the problem will be easy like adding 97 and 3.

##### Clone this wiki locally
You can’t perform that action at this time.