> For the complete documentation index, see [llms.txt](https://sandeepamaranath.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandeepamaranath.gitbook.io/notes/data-structures/leetcode.md).

# LeetCode ✅😎😎

## How did I select the below questions?

Let's first focus on solving these questions. I selected them from various places including Udemy courses where they had marked these as popular questions. So, I'm sure these would help me a lot.

{% embed url="<https://docs.google.com/document/d/1SM92efk8oDl8nyVw8NHPnbGexTS9W-1gmTEYfEurLWQ/edit>" %}

## How to select Leetcode questions for interviews?&#x20;

### Read  Algo monster blog below

{% embed url="<https://leetcode.algo.monster/stop-leetcode-grind/?utm_source={google}&utm_term=leetcode&utm_campaign=leetcode_broad&utm_source=google&utm_term=leetcode&gclid=Cj0KCQjwwLKFBhDPARIsAPzPi-Ir9Mo4II5tmopqmSoxw-QSBfJkecfdZ85WUuW082PS3gLaTqcKbtcaAiz3EALw_wcB>" %}
Algo monster 1
{% endembed %}

{% embed url="<https://algo.monster/problems/google_online_assessment_questions>" %}
Algo monster 2
{% endembed %}

#### Questions I would solve. This list will increase as I go and I keep adding the new questions and also the info where I found it saying they are useful.

| Questions (E- Easy, M-Med, H-Hard)                       | Topics                                      | Who said this is important                                                                        |
| -------------------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| 283 (E), 881(M), 941 (E), 11(M), 3(M), 34(M), 278(E)     | Arrays and Strings(Includes Google asked)   | Udemy <https://www.udemy.com/course/leetcode-in-python-50-algorithms-coding-interview-questions/> |
| 268(E), 204(E), 136(E), 657(E)                           | Math(Includes Microsoft asked)              |                                                                                                   |
| 1(E), 217(E), 169(E), 49(M), 454(M), 146(M), 76(H)       | Hashtables / Maps(Includes Facebook asked)  |                                                                                                   |
| 21(E), 141(E), 206(E), 2(M), 19(M), 328(M), 23(H)        | Linked List (Includes Amazon asked)         |                                                                                                   |
| 78(M), 17(M), 79(M), 39(M), 131(M)                       | Backtracking (Includes Uber asked)          |                                                                                                   |
| 101(E), 104(E), 112(E), 236(M), 230(M), 297(H), 124(H)   | Trees and Graphs(Includes Apple asked)      |                                                                                                   |
| 155(E), 20(E), 102(M), 103(M), 145(M)                    | Stacks and Queues(Includes Bloomberg asked) |                                                                                                   |
| 198(E), 121(E), 70(E), 322(M), 62(M), 5(M), 42(H), 42(H) | Dynamic Programming(Includes Google asked)  |                                                                                                   |

### Amazon LeetCode Questions (72 questions)

![Amazon leetcode questions](/files/-MaBCfMYB6XmF2nop1wA)

## Video Explanation&#x20;

### 1. Two Sum - Easy (Array)

{% embed url="<https://www.youtube.com/watch?v=U8B984M1VcU&ab_channel=TerribleWhiteboardTerribleWhiteboard>" %}
Two Sum
{% endembed %}

[`array`](https://leetcode.com/tag/array) | [`hash-table`](https://leetcode.com/tag/hash-table)

### 2. Add Two Numbers - Medium (Linked List)

{% embed url="<https://www.youtube.com/watch?v=1Spw7DEtB14&ab_channel=TerribleWhiteboard>" %}
Add Two Numbers
{% endembed %}

[`linked-list`](https://leetcode.com/tag/linked-list) | [`math`](https://leetcode.com/tag/math)

### 3. Longest Substring without repeating characters - Medium (Strings)

{% embed url="<https://www.youtube.com/watch?v=WKTgajDkVcA&ab_channel=TerribleWhiteboardTerribleWhiteboard>" %}

[`hash-table`](https://leetcode.com/tag/hash-table) | [`two-pointers`](https://leetcode.com/tag/two-pointers) | [`string`](https://leetcode.com/tag/string) | [`sliding-window`](https://leetcode.com/tag/sliding-window)

### 5. [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring) And[ 647. Palindromic Substrings](https://www.youtube.com/watch?v=EIf9zFqufbU\&t=779s)

```javascript
const matrix = []
const str = "babad";
let count = 0;
let palindromes = [];
let longestPal = "" // longest palindromic substring

for (const ch of str) {
    matrix.push(new Array(str.length).fill(0))
}
//set diagonals to 1
for (let diag = 0; diag < str.length; diag++) {
    matrix[diag][diag] = 1
}

//set 1 in grid above diagonal
for (let col = 1; col < str.length; col++) {
    for (row = 0; row < col; row++) {
        if (row === col - 1 && str[row] === str[col]) {
            matrix[row][col] = 1
            count++;
            palindromes.push(str.slice(row, col + 1))
            if (str.slice(row, col + 1) > longestPal.length) {
                longestPal = str.slice(row, col + 1)
            }
        } else if (matrix[row + 1][col - 1] === 1 && str[row] === str[col]) {
            matrix[row][col] = 1
            count++;
            palindromes.push(str.slice(row, col + 1))
            if (str.slice(row, col + 1).length > longestPal.length) {
                longestPal = str.slice(row, col + 1)
            }
        }
    }
}
// (0,2) -> (1,1) -> (row=0,col=2) chk for (row=1,col=1)
const printMatrix = () => {
    for (let row = 0; row < str.length; row++) {
        let rowStr = ''
        for (let col = 0; col < str.length; col++) {
            rowStr += matrix[row][col] + (col !== str.length - 1 ? " | " : "")
        }
        console.log(`${row}       | ${rowStr} |`)
        console.log("-".repeat(23).padStart(30, " "))
    }
}

printMatrix()
console.log(palindromes) // all the palindromes
console.log(`The longest palindrome is ${longestPal}`) // longest palindrome
```
