> For the complete documentation index, see [llms.txt](https://amartyushov.gitbook.io/tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amartyushov.gitbook.io/tech/computer-science/general-notes-1/howto-algorithms-for-interview.md).

# HowTo algorithms for interview

## Как строится алгоритмическая секция интервью

[Курс от Яндекса "Подготовка к алгоритмическому собеседованию"](https://practicum.yandex.ru/algorithms-interview/)

[Big-O Complexity Chart](https://www.bigocheatsheet.com/)

### What

Несколько задач на время. Даны входные и выходные данные. Написать алгоритм

### Как решать задачи

#### Практика

* **(priority 0)** [Neetcode](https://neetcode.io/) Платформа с подборками зада по темам с ссылками на Leetcode
* **(priority 1)** [Таблица](https://seanprashad.com/leetcode-patterns/) с сортировкой по Leedcode задачам (сложность, компания)
  * Blind 75: просто ссылки на Leetcode [ОТСЮДА](https://www.teamblind.com/post/New-Year-Gift---Curated-List-of-Top-75-LeetCode-Questions-to-Save-Your-Time-OaM1orEU) (не указана сложность)
  * Blind 75: [видео разбор всех задач](https://www.youtube.com/playlist?list=PLot-Xpze53ldVwtstag2TL4HQhAnC8ATf) на Python
* **(priority 2)** Как повторение 75 задач, для того чтобы перерешать [Grind75](https://www.techinterviewhandbook.org/grind75)
* **(priority 3)** [Курс от Яндекса](https://academy.yandex.ru/handbook/algorithms) "Основы алгоритмов"

Теория

* **(priority 1)** [Overview](https://www.byte-by-byte.com/data-structures/) for data structures with links to try challenges
* **(priority 2)** [Guided list](https://github.com/jwasham/coding-interview-university#lets-get-started) for learning algorithms and data structures
* **(priority 3)** [Разбор задач, ](https://github.com/labuladong/fucking-algorithm/tree/english)подходов к решению (есть визуализация, но местами по-китайски)
  * скорее средняя сложность задач и выше
* **(priority 3)** [видео разбор задач](https://github.com/jwasham/coding-interview-university#coding-problems)
* **(priority 3)** [Разбор задач](https://github.com/vitkarpov/coding-interviews-blog-archive/blob/main/posts/cache.md) на русском

Использованы статьи для составления плана [ССЫЛКА](https://telegra.ph/Algoritmicheskoe-intervyu-08-28-2)

## Plan for now

1. go through templates [LINK](https://leetcode.com/explore/interview/card/cheatsheets/720/resources/4725/)
2. :white\_check\_mark:Go through <https://seanprashad.com/leetcode-patterns/>
3. :white\_check\_mark:Heap, trees, graph, DP
4. top easy collection <https://leetcode.com/explore/featured/card/top-interview-questions-easy/>
5. :white\_check\_mark:Heap in details <https://leetcode.com/explore/learn/card/heap/643/heap/4018/>
6. sorting <https://leetcode.com/explore/learn/card/sorting/>

#### Рекомендуем повторить все, что связано с алгоритмами:

* основные структуры данных — :white\_check\_mark: строки, :white\_check\_mark:списки (LinkedList), деревья, :white\_check\_mark:ассоциативные массивы (HashMap, TreeMap, LinkedHashMap), векторы;
* базовые алгоритмы — поиск элементов в коллекциях, обход деревьев, сортировки, динамическое программирование;
* :white\_check\_mark:понятие сложности алгоритмов, O-нотация.

#### :white\_check\_mark:Пример задачи

Даны три неубывающих массива чисел. Найти число, которое присутствует во всех трех массивах.

```
Input: [1,2,4,5], [3,3,4], [2,3,4,5,6]
Output: 4
```

Целевое решение работает за O(p + q + r), где p, q, r – длины массивов, доп. память O(1), но эту информацию интервьюер не сообщает.

```java
public int findCommonElement(int[] arr1, int[] arr2, int[] arr3) {
        int p1 = 0, p2 = 0, p3 = 0;

        while (p1 < arr1.length && p2 < arr2.length && p3 < arr3.length) {
            if (arr1[p1] == arr2[p2] && arr2[p2] == arr3[p3]) {
                return arr1[p1];
            } else if (arr1[p1] <= arr2[p2] && arr1[p1] <= arr3[p3]) {
                p1++;
            } else if (arr2[p2] <= arr1[p1] && arr2[p2] <= arr3[p3]) {
                p2++;
            } else {
                p3++;
            }
        }
        return -1; // Если нет общего числа во всех трех массивах
    }
```

##
