master 809d75c64213 cached
55 files
329.4 KB
90.4k tokens
1 requests
Download .txt
Showing preview only (348K chars total). Download the full file or copy to clipboard to get everything.
Repository: kiranpalsingh1806/awesome-leetcode
Branch: master
Commit: 809d75c64213
Files: 55
Total size: 329.4 KB

Directory structure:
gitextract_fbu3irtf/

├── README.md
├── markdown/
│   ├── code-2.md
│   └── code.md
├── random/
│   ├── Random.md
│   └── SOLUTIONS.md
└── solutions/
    ├── base-conversion.md
    ├── bellman-ford.md
    ├── binary-trees.md
    ├── bit-manipulation.md
    ├── custom-comparator.md
    ├── design.md
    ├── dfs.md
    ├── dijksta.md
    ├── dp.md
    ├── euler-circuit.md
    ├── fenwick-tree.md
    ├── heaps/
    │   ├── kth-largest-element-in-array.md
    │   ├── sort-array-by-increasing-frequency.md
    │   ├── sort-characters-by-frequency.md
    │   └── top-k-frequent-elements.md
    ├── intervals.md
    ├── kruskal.md
    ├── line-sweep.md
    ├── linked-list.md
    ├── lis.md
    ├── manacher.md
    ├── matrix.md
    ├── merge-sort.md
    ├── prefix-state-map.md
    ├── queries.md
    ├── rolling-hash/
    │   ├── distinct-echo-substrings.md
    │   ├── find-substring-with-given-hash-value.md
    │   ├── k-divisible-elements-subarray.md
    │   ├── longest-common-subpath.md
    │   ├── longest-duplicate-substring.md
    │   ├── repeated-dna-sequences.md
    │   ├── shortest-palindrome.md
    │   └── sum-of-scores-of-built-strings.md
    ├── segment-tree.md
    ├── sets.md
    ├── sieve-eratosthenes.md
    ├── sliding-window/
    │   └── count-subarrays-with-fixed-count.md
    ├── sliding-window.md
    ├── stack.md
    ├── stringstream.md
    ├── sum-of-first-n-natural-numbers.md
    ├── topological-sort.md
    └── trie/
        ├── concatenated-words.md
        ├── implement-trie.md
        ├── k-divisible-elements-subarrays.md
        ├── maximum-genetic-difference-query.md
        ├── maximum-xor-of-two-numbers.md
        ├── palindrome-pairs.md
        ├── search-suggestions-system.md
        └── sum-of-prefix-scores-of-strings.md

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
<div align="center">
<h1>Awesome Leetcode</h1>

<a href="https://github.com/kiranpalsingh1806/awesome-leetcode"><img src="https://sloc.xyz/github/kiranpalsingh1806/awesome-leetcode" alt="LOC"/></a>
<a href="https://github.com/kiranpalsingh1806/awesome-leetcode"><img src="https://visitor-badge.laobi.icu/badge?page_id=kiranpalsingh1806.awesome-leetcode" alt="visitor count"/></a>
<a href="https://github.com/kiranpalsingh1806/awesome-leetcode/stargazers"><img src="https://img.shields.io/github/stars/kiranpalsingh1806/awesome-leetcode" alt="Stars Badge"/></a>
<a href="https://github.com/kiranpalsingh1806/awesome-leetcode/network/members"><img src="https://img.shields.io/github/forks/kiranpalsingh1806/awesome-leetcode" alt="Forks Badge"/></a>
<a href="https://github.com/kiranpalsingh1806/awesome-leetcode/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors/kiranpalsingh1806/awesome-leetcode?color=2b9348"></a>

<b><i>If you appreciate my work, please</i></b> 🌟 <b><i>this repository. It motivates me. 🚀🚀</i></b>

</div>

- [1. Backtracking](#1-backtracking)
- [2. Base Conversion](#2-base-conversion)
- [3. Bellman Ford](#3-bellman-ford)
- [4. BFS](#4-bfs)
- [5. Binary Search](#5-binary-search)
- [6. Binary Trees](#6-binary-trees)
- [7. Bit Manipulation](#7-bit-manipulation)
- [8. Bitmasks](#8-bitmasks)
- [9. Count Pairs In Array](#9-count-pairs-in-array)
- [10. Custom Comparator](#10-custom-comparator)
- [11. Design and Implementation](#11-design-and-implementation)
- [12. DFS](#12-dfs)
- [13. Dijkstra](#13-dijkstra)
- [14. Dynamic Programming](#14-dynamic-programming)
- [15. Euler Circuit](#15-euler-circuit)
- [16. Fenwick Tree](#16-fenwick-tree)
- [17. Greedy Scheduling](#17-greedy-scheduling)
- [18. Heaps (Priority Queues)](#18-heaps-priority-queues)
- [19. Intervals](#19-intervals)
- [20. Line Sweep](#20-line-sweep)
- [21. Linked List](#21-linked-list)
- [22. LIS](#22-lis)
- [23. Manacher](#23-manacher)
- [24. Matrix](#24-matrix)
- [25. Merge Sort](#25-merge-sort)
- [26. Minimum Spanning Trees](#26-minimum-spanning-trees)
- [27. Prefix State Map](#27-prefix-state-map)
- [28. Queries](#28-queries)
- [29. Rolling Hash](#29-rolling-hash)
- [30. Segment Tree](#30-segment-tree)
- [31. Sets](#31-sets)
- [32. Sieve of Eratosthenes](#32-sieve-of-eratosthenes)
- [33. Sliding Window](#33-sliding-window)
- [34. Stack](#34-stack)
- [35. Stringstream](#35-stringstream)
- [36. Sum of First N Natural Numbers](#36-sum-of-first-n-natural-numbers)
- [37. Topological Sort](#37-topological-sort)
- [38. Trie](#38-trie)
- [39. Two Dimensional Plane](#39-two-dimensional-plane)
- [40. Two Pointer](#40-two-pointer)
- [41. Union Find](#41-union-find)

## 1. Backtracking

| S.No | Problem                                                                                                       | Difficulty | Solution                                                                              |
| ---- | ------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Combination Sum](https://leetcode.com/problems/combination-sum/)                                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 3    | [Permutations](https://leetcode.com/problems/permutations/)                                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 4    | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 5    | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 6    | [Sudoku Solver](https://leetcode.com/problems/sudoku-solver/)                                                 | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 7    | [Combination Sum II](https://leetcode.com/problems/combination-sum-ii/)                                       | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 8    | [Permutations II](https://leetcode.com/problems/permutations-ii/)                                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 9    | [N Queens](https://leetcode.com/problems/n-queens/)                                                           | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 10   | [Combinations](https://leetcode.com/problems/combinations/)                                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 11   | [Subsets](https://leetcode.com/problems/subsets/)                                                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 12   | [Word Search](https://leetcode.com/problems/word-search/)                                                     | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 13   | [Subsets II](https://leetcode.com/problems/subsets-ii/)                                                       | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 14   | [Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning/)                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 15   | [Combination Sum III ](https://leetcode.com/problems/combination-sum-iii/)                                    | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 2. Base Conversion

| S.No | Problem                                                                                           | Difficulty | Solution                                  |
| ---- | ------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------- |
| 1    | [Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/description/) | Medium     | [Solution](/solutions/base-conversion.md) |

## 3. Bellman Ford

| S.No | Problem                                                                                           | Difficulty | Solution                               |
| ---- | ------------------------------------------------------------------------------------------------- | ---------- | -------------------------------------- |
| 1    | [Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/) | Medium     | [Solution](/solutions/bellman-ford.md) |
| 2    | [Network Delay Time](https://leetcode.com/problems/network-delay-time/)                           | Medium     | [Solution](/solutions/bellman-ford.md) |

## 4. BFS

| S.No | Problem                                                                                             | Difficulty | Solution                                                                              |
| ---- | --------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Average of Levels In Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/) | Easy       | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Number of Islands](https://leetcode.com/problems/number-of-islands/)                               | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 5. Binary Search

| S.No | Problem                                                                                                                                           | Difficulty | Solution                                                                              |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Search In Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/)                                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Find First and Last Position of Element In Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 3    | [Minimize Maximum of Array](https://leetcode.com/problems/minimize-maximum-of-array/)                                                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 6. Binary Trees

| S.No | Problem                                                                                                                                                 | Difficulty | Solution                               |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | -------------------------------------- |
| 1    | [Sum of Leaft Leaves](https://leetcode.com/problems/sum-of-left-leaves/)                                                                                | Easy       | [Solution](/solutions/binary-trees.md) |
| 2    | [Construct String From Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree/)                                                   | Easy       | [Solution](/solutions/binary-trees.md) |
| 3    | [Average of Levels In Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/)                                                     | Easy       | [Solution](/solutions/binary-trees.md) |
| 4    | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/)                                                                             | Easy       | [Solution](/solutions/binary-trees.md) |
| 5    | [Convert Sorted Array To Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/)                                 | Easy       | [Solution](/solutions/binary-trees.md) |
| 6    | [Sum Root To Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/)                                                                     | Medium     | [Solution](/solutions/binary-trees.md) |
| 7    | [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/)                                                           | Medium     | [Solution](/solutions/binary-trees.md) |
| 8    | [Lowest Common Ancestor Of A Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)                                       | Medium     | [Solution](/solutions/binary-trees.md) |
| 9    | [Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst/)                                                           | Medium     | [Solution](/solutions/binary-trees.md) |
| 10   | [Construct Binary Tree From Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium     | [Solution](/solutions/binary-trees.md) |
| 11   | [Construct Binary Tree From Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/)   | Medium     | [Solution](/solutions/binary-trees.md) |
| 12   | [Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/)                                                                               | Medium     | [Solution](/solutions/binary-trees.md) |
| 13   | [All Nodes Distance K In Binary Tree](https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/)                                               | Medium     | [Solution](/solutions/binary-trees.md) |
| 14   | [Distribute Coins In Binary Tree](https://leetcode.com/problems/distribute-coins-in-binary-tree/)                                                       | Medium     | [Solution](/solutions/binary-trees.md) |
| 15   | [Vertical Order Traversal of A Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/)                                   | Hard       | [Solution](/solutions/binary-trees.md) |

## 7. Bit Manipulation

| S.No | Problem                                                                                                                                         | Difficulty | Solution                                   |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------ |
| 1    | [Power of Two](https://leetcode.com/problems/power-of-two/)                                                                                     | Easy       | [Solution](/solutions/bit-manipulation.md) |
| 2    | [Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs/)                                                   | Easy       | [Solution](/solutions/bit-manipulation.md) |
| 3    | [Divide Two Integers](https://leetcode.com/problems/divide-two-integers/)                                                                       | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 4    | [Subsets](https://leetcode.com/problems/subsets/)                                                                                               | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 5    | [Subsets II](https://leetcode.com/problems/subsets-ii/)                                                                                         | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 6    | [Check If A String Contains All Binary Codes of Size K](https://leetcode.com/problems/check-if-a-string-contains-all-binary-codes-of-size-k/)   | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 7    | [Concatenation of Consecutive Binary Numbers](https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/)                       | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 8    | [Count Number of Maximum Bitwise OR Subsets](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/)                         | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 9    | [Largest Combination With Bitwise AND Greater Than Zero](https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/) | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 10   | [Maximum XOR After Operations](https://leetcode.com/problems/maximum-xor-after-operations/)                                                     | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 11   | [Smallest Subarrays With Maximum Bitwise OR](https://leetcode.com/problems/smallest-subarrays-with-maximum-bitwise-or/)                         | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 12   | [Longest Subarray With Maximum Bitwise AND](https://leetcode.com/problems/longest-subarray-with-maximum-bitwise-and/)                           | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 13   | [Minimize XOR](https://leetcode.com/problems/minimize-xor/)                                                                                     | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 14   | [Bitwise XOR of All Pairings](https://leetcode.com/problems/bitwise-xor-of-all-pairings/)                                                       | Medium     | [Solution](/solutions/bit-manipulation.md) |
| 15   | [Closest Subsequence Sum](https://leetcode.com/problems/closest-subsequence-sum/)                                                               | Hard       | [Solution](/solutions/bit-manipulation.md) |
| 16   | [Find The Shortest Superstring](https://leetcode.com/problems/find-the-shortest-superstring/)                                                   | Hard       | [Solution](/solutions/bit-manipulation.md) |
| 17   | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits/)                                                                           | Easy       | [Solution](/solutions/bit-manipulation.md) |

## 8. Bitmasks

| S.No | Problem                                                                                                                 | Difficulty | Solution                                                                              |
| ---- | ----------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Fair Distribution of Cookies](https://leetcode.com/problems/fair-distribution-of-cookies/)                             | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Count Number of Maximum Bitwise OR Subsets](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 9. Count Pairs In Array

| S.No | Problem                                                                                     | Difficulty | Solution                                                                              |
| ---- | ------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Count Nice Pairs In An Array](https://leetcode.com/problems/count-nice-pairs-in-an-array/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Count Number of Bad Pairs](https://leetcode.com/problems/count-number-of-bad-pairs/)       | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 10. Custom Comparator

| S.No | Problem                                                                                   | Difficulty | Solution                                    |
| ---- | ----------------------------------------------------------------------------------------- | ---------- | ------------------------------------------- |
| 1    | [Sort The People](https://leetcode.com/problems/sort-the-people/)                         | Medium     | [Solution](/solutions/custom-comparator.md) |
| 2    | [Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/)               | Medium     | [Solution](/solutions/custom-comparator.md) |
| 3    | [Bitwise XOR of All Pairings](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | Medium     | [Solution](/solutions/custom-comparator.md) |

## 11. Design and Implementation

| S.No | Problem                                                                                     | Difficulty | Solution                         |
| ---- | ------------------------------------------------------------------------------------------- | ---------- | -------------------------------- |
| 1    | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/) | Easy       | [Solution](/solutions/design.md) |
| 2    | [Implement Stack Using Queues](https://leetcode.com/problems/implement-stack-using-queues/) | Easy       | [Solution](/solutions/design.md) |
| 3    | [Stock Price Fluctuation](https://leetcode.com/problems/stock-price-fluctuation/)           | Medium     | [Solution](/solutions/design.md) |
| 4    | [Design Circular Deque](https://leetcode.com/problems/design-circular-deque/)               | Medium     | [Solution](/solutions/design.md) |
| 5    | [LRU Cache](https://leetcode.com/problems/lru-cache/)                                       | Medium     | [Solution](/solutions/design.md) |
| 6    | [Time Based Key Value Store](https://leetcode.com/problems/time-based-key-value-store/)     | Medium     | [Solution](/solutions/design.md) |
| 7    | [Operations On Tree](https://leetcode.com/problems/operations-on-tree/)                     | Medium     | [Solution](/solutions/design.md) |
| 8    | [Design Circular Queue](https://leetcode.com/problems/design-circular-queue/)               | Medium     | [Solution](/solutions/design.md) |
| 9    | [Design Movie Rental System](https://leetcode.com/problems/design-movie-rental-system/)     | Hard       | [Solution](/solutions/design.md) |
| 10   | [Design A Text Editor](https://leetcode.com/problems/design-a-text-editor/)                 | Hard       | [Solution](/solutions/design.md) |

## 12. DFS

| S.No | Problem                                                                                                                           | Difficulty | Solution                      |
| ---- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------- |
| 1    | [Flood Fill](https://leetcode.com/problems/flood-fill/)                                                                           | Easy       | [Solution](/solutions/dfs.md) |
| 2    | [Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/)                                                          | Medium     | [Solution](/solutions/dfs.md) |
| 3    | [Keys and Rooms](https://leetcode.com/problems/keys-and-rooms/)                                                                   | Medium     | [Solution](/solutions/dfs.md) |
| 4    | [Out of Boundary Paths](https://leetcode.com/problems/out-of-boundary-paths/)                                                     | Medium     | [Solution](/solutions/dfs.md) |
| 5    | [Number of Provinces](https://leetcode.com/problems/number-of-provinces/)                                                         | Medium     | [Solution](/solutions/dfs.md) |
| 6    | [Pacific Atlantic Water Flow](https://leetcode.com/problems/pacific-atlantic-water-flow/)                                         | Medium     | [Solution](/solutions/dfs.md) |
| 7    | [Interleaving String](https://leetcode.com/problems/interleaving-string/)                                                         | Medium     | [Solution](/solutions/dfs.md) |
| 8    | [Shortest Bridge](https://leetcode.com/problems/shortest-bridge/)                                                                 | Medium     | [Solution](/solutions/dfs.md) |
| 9    | [Throne Inheritance](https://leetcode.com/problems/throne-inheritance/)                                                           | Medium     | [Solution](/solutions/dfs.md) |
| 10   | [Detonate The Maximum Bombs](https://leetcode.com/problems/detonate-the-maximum-bombs/)                                           | Medium     | [Solution](/solutions/dfs.md) |
| 11   | [Longest Path With Different Adjacent Characters](https://leetcode.com/problems/longest-path-with-different-adjacent-characters/) | Hard       | [Solution](/solutions/dfs.md) |
| 12   | [Create Components With Same Value](https://leetcode.com/problems/create-components-with-same-value/)                             | Hard       | [Solution](/solutions/dfs.md) |
| 13   | [Restore the Array From Adjacent Pairs](https://leetcode.com/problems/restore-the-array-from-adjacent-pairs/description/)         | Medium     | [Solution](/solutions/dfs.md) |

## 13. Dijkstra

| S.No | Problem                                                                                                                                                                                   | Difficulty | Solution                          |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------- |
| 1    | [Network Delay Time](https://leetcode.com/problems/network-delay-time/)                                                                                                                   | Medium     | [Solution](/solutions/dijksta.md) |
| 2    | [Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/)                                                                                         | Medium     | [Solution](/solutions/dijksta.md) |
| 3    | [Path With Maximum Probability](https://leetcode.com/problems/path-with-maximum-probability/)                                                                                             | Medium     | [Solution](/solutions/dijksta.md) |
| 4    | [Find The City With The Smallest Number of Neighbors At A Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/) | Medium     | [Solution](/solutions/dijksta.md) |
| 5    | [Path With Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/)                                                                                                       | Medium     | [Solution](/solutions/dijksta.md) |
| 6    | [Number of Restricted Paths From First To Last Node](https://leetcode.com/problems/number-of-restricted-paths-from-first-to-last-node/)                                                   | Medium     | [Solution](/solutions/dijksta.md) |
| 7    | [Number of Ways To Arrive At Destination](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/)                                                                         | Medium     | [Solution](/solutions/dijksta.md) |
| 8    | [Minimum Cost To Reach Destination In Time](https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/)                                                                     | Medium     | [Solution](/solutions/dijksta.md) |
| 9    | [Minimum Cost To Make At Least One Valid Path In A Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/)                                           | Hard       | [Solution](/solutions/dijksta.md) |
| 10   | [Reachable Nodes in Subdivided Graph](https://leetcode.com/problems/reachable-nodes-in-subdivided-graph/)                                                                                 | Hard       | [Solution](/solutions/dijksta.md) |
| 11   | [Design Graph With Shortest Path Calculator](https://leetcode.com/problems/design-graph-with-shortest-path-calculator/)                                                                   | Hard       | [Solution](/solutions/dijksta.md) |

## 14. Dynamic Programming

| S.No | Problem                                                                                           | Difficulty | Solution                     |
| ---- | ------------------------------------------------------------------------------------------------- | ---------- | ---------------------------- |
| 1    | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)                                 | Easy       | [Solution](/solutions/dp.md) |
| 2    | [Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)                              | Easy       | [Solution](/solutions/dp.md) |
| 3    | [Best Time To Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | Easy       | [Solution](/solutions/dp.md) |
| 4    | [Jump Game](https://leetcode.com/problems/jump-game/)                                             | Medium     | [Solution](/solutions/dp.md) |
| 5    | [Unique Paths](https://leetcode.com/problems/unique-paths/)                                       | Medium     | [Solution](/solutions/dp.md) |
| 6    | [Decode Ways](https://leetcode.com/problems/decode-ways/)                                         | Medium     | [Solution](/solutions/dp.md) |
| 7    | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)               | Medium     | [Solution](/solutions/dp.md) |
| 8    | [House Robber](https://leetcode.com/problems/house-robber/)                                       | Medium     | [Solution](/solutions/dp.md) |
| 9    | [Word Break](https://leetcode.com/problems/word-break/)                                           | Medium     | [Solution](/solutions/dp.md) |
| 10   | [Coin Change](https://leetcode.com/problems/coin-change/)                                         | Medium     | [Solution](/solutions/dp.md) |
| 11   | [Count Number of Texts](https://leetcode.com/problems/count-number-of-texts/description/)         | Medium     | [Solution](/solutions/dp.md) |

## 15. Euler Circuit

| S.No | Problem                                                                                 | Difficulty | Solution                                |
| ---- | --------------------------------------------------------------------------------------- | ---------- | --------------------------------------- |
| 1    | [Reconstruct Itinerary](https://leetcode.com/problems/reconstruct-itinerary/)           | Hard       | [Solution](/solutions/euler-circuit.md) |
| 2    | [Cracking The Safe](https://leetcode.com/problems/cracking-the-safe/)                   | Hard       | [Solution](/solutions/euler-circuit.md) |
| 3    | [Valid Arrangement of Pairs](https://leetcode.com/problems/valid-arrangement-of-pairs/) | Hard       | [Solution](/solutions/euler-circuit.md) |

## 16. Fenwick Tree

| S.No | Problem                                                                                                             | Difficulty | Solution                               |
| ---- | ------------------------------------------------------------------------------------------------------------------- | ---------- | -------------------------------------- |
| 1    | [Shifting Letters II](https://leetcode.com/problems/shifting-letters-ii/)                                           | Medium     | [Solution](/solutions/fenwick-tree.md) |
| 2    | [Queries On A Permutation With Key](https://leetcode.com/problems/queries-on-a-permutation-with-key/)               | Medium     | [Solution](/solutions/fenwick-tree.md) |
| 3    | [Create Sorted Array Through Instructions](https://leetcode.com/problems/create-sorted-array-through-instructions/) | Hard       | [Solution](/solutions/fenwick-tree.md) |
| 4    | [Count Good Triplets In An Array](https://leetcode.com/problems/count-good-triplets-in-an-array/)                   | Hard       | [Solution](/solutions/fenwick-tree.md) |

## 17. Greedy Scheduling

| S.No | Problem                                                                                                                       | Difficulty | Solution                                                                              |
| ---- | ----------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Maximum Number of Events That Can Be Attended](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Single Threaded CPU](https://leetcode.com/problems/single-threaded-cpu/)                                                     | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 18. Heaps (Priority Queues)

| S.No | Problem                                                                                                                                     | Difficulty | Solution                                                           |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------ |
| 1    | [Sort Array By Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency/)                                     | Easy       | [Solution](/solutions/heaps/sort-array-by-increasing-frequency.md) |
| 2    | [Kth Largest Element in An Array](https://leetcode.com/problems/kth-largest-element-in-an-array/)                                           | Medium     | [Solution](/solutions/heaps/kth-largest-element-in-array.md)       |
| 3    | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)                                                           | Medium     | [Solution](/solutions/heaps/top-k-frequent-elements.md)            |
| 4    | [Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency/)                                                 | Medium     | [Solution](/solutions/heaps/sort-characters-by-frequency.md)       |
| 5    | [Find K Closest Elements](https://leetcode.com/problems/find-k-closest-elements/)                                                           | Medium     | [Solution](/solutions/heaps)                                       |
| 6    | [Top K Frequent Words](https://leetcode.com/problems/top-k-frequent-words/)                                                                 | Medium     | [Solution](/solutions/heaps)                                       |
| 7    | [K Closest Points To Origin](https://leetcode.com/problems/k-closest-points-to-origin/)                                                     | Medium     | [Solution](/solutions/heaps)                                       |
| 8    | [Reduce Array Size To The Half](https://leetcode.com/problems/reduce-array-size-to-the-half/)                                               | Medium     | [Solution](/solutions/heaps)                                       |
| 9    | [Reorganize String](https://leetcode.com/problems/reorganize-string/)                                                                       | Medium     | [Solution](/solutions/heaps)                                       |
| 10   | [Sender With Largest Word Count](https://leetcode.com/problems/sender-with-largest-word-count/)                                             | Medium     | [Solution](/solutions/heaps)                                       |
| 11   | [Minimum Difference In Sums After Removal of Elements](https://leetcode.com/problems/minimum-difference-in-sums-after-removal-of-elements/) | Hard       | [Solution](/solutions/heaps)                                       |
| 12   | [Course Schedule III](https://leetcode.com/problems/course-schedule-iii/)                                                                   | Hard       | [Solution](/solutions/heaps)                                       |
| 13   | [Maximum Frequency Stack](https://leetcode.com/problems/maximum-frequency-stack/)                                                           | Hard       | [Solution](/solutions/heaps)                                       |

## 19. Intervals

| S.No | Problem                                                                                                                 | Difficulty | Solution                            |
| ---- | ----------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------- |
| 1    | [Merge Intervals](https://leetcode.com/problems/merge-intervals/)                                                       | Medium     | [Solution](/solutions/intervals.md) |
| 2    | [Insert Interval](https://leetcode.com/problems/insert-interval/)                                                       | Medium     | [Solution](/solutions/intervals.md) |
| 3    | [Non Overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/)                                   | Medium     | [Solution](/solutions/intervals.md) |
| 4    | [Minimum Number of Arrows To Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/) | Medium     | [Solution](/solutions/intervals.md) |
| 5    | [My Calendar I](https://leetcode.com/problems/my-calendar-i/)                                                           | Medium     | [Solution](/solutions/intervals.md) |
| 6    | [Video Stitching](https://leetcode.com/problems/video-stitching/)                                                       | Medium     | [Solution](/solutions/intervals.md) |

## 20. Line Sweep

| S.No | Problem                                                                                                                         | Difficulty | Solution                             |
| ---- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------ |
| 1    | [Maximum Population Year](https://leetcode.com/problems/maximum-population-year/)                                               | Easy       | [Solution](/solutions/line-sweep.md) |
| 2    | [Divide Intervals Into Minimum Number of Groups](https://leetcode.com/problems/divide-intervals-into-minimum-number-of-groups/) | Medium     | [Solution](/solutions/line-sweep.md) |
| 3    | [Shifting Letters II](https://leetcode.com/problems/shifting-letters-ii/)                                                       | Medium     | [Solution](/solutions/line-sweep.md) |
| 4    | [Describe The Painting](https://leetcode.com/problems/describe-the-painting/)                                                   | Medium     | [Solution](/solutions/line-sweep.md) |
| 5    | [Minimum Absolute Difference Queries](https://leetcode.com/problems/minimum-absolute-difference-queries/)                       | Medium     | [Solution](/solutions/line-sweep.md) |
| 6    | [Car Pooling](https://leetcode.com/problems/car-pooling/)                                                                       | Medium     | [Solution](/solutions/line-sweep.md) |
| 7    | [Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings/)                                           | Medium     | [Solution](/solutions/line-sweep.md) |
| 8    | [My Calendar II](https://leetcode.com/problems/my-calendar-ii/)                                                                 | Medium     | [Solution](/solutions/line-sweep.md) |
| 9    | [Minimum Interval To Include Each Query](https://leetcode.com/problems/minimum-interval-to-include-each-query/)                 | Hard       | [Solution](/solutions/line-sweep.md) |
| 10   | [My Calendar III](https://leetcode.com/problems/my-calendar-iii/)                                                               | Hard       | [Solution](/solutions/line-sweep.md) |
| 11   | [The Skyline Problem](https://leetcode.com/problems/the-skyline-problem/)                                                       | Hard       | [Solution](/solutions/line-sweep.md) |
| 12   | [Number of Flowers In Full Bloom](https://leetcode.com/problems/number-of-flowers-in-full-bloom/)                               | Hard       | [Solution](/solutions/line-sweep.md) |

## 21. Linked List

| S.No | Problem                                                                                                                   | Difficulty | Solution                              |
| ---- | ------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------- |
| 1    | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)                                           | Easy       | [Solution](/solutions/linked-list.md) |
| 2    | [Remove Duplicates From Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)                   | Easy       | [Solution](/solutions/linked-list.md) |
| 3    | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)                                                     | Easy       | [Solution](/solutions/linked-list.md) |
| 4    | [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)                                           | Easy       | [Solution](/solutions/linked-list.md) |
| 5    | [Middle of The Linked List](https://leetcode.com/problems/middle-of-the-linked-list/)                                     | Easy       | [Solution](/solutions/linked-list.md) |
| 6    | [Intersection of Two Linked List](https://leetcode.com/problems/intersection-of-two-linked-lists/)                        | Easy       | [Solution](/solutions/linked-list.md) |
| 7    | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)                                                         | Medium     | [Solution](/solutions/linked-list.md) |
| 8    | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)                       | Medium     | [Solution](/solutions/linked-list.md) |
| 9    | [Rotate List](https://leetcode.com/problems/rotate-list/)                                                                 | Medium     | [Solution](/solutions/linked-list.md) |
| 10   | [Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list/)                       | Medium     | [Solution](/solutions/linked-list.md) |
| 11   | [Sort List](https://leetcode.com/problems/sort-list/)                                                                     | Medium     | [Solution](/solutions/linked-list.md) |
| 12   | [Reorder List](https://leetcode.com/problems/reorder-list/)                                                               | Medium     | [Solution](/solutions/linked-list.md) |
| 13   | [Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/)                                               | Medium     | [Solution](/solutions/linked-list.md) |
| 14   | [Remove Duplicates From Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/)             | Medium     | [Solution](/solutions/linked-list.md) |
| 15   | [Partition List](https://leetcode.com/problems/partition-list/)                                                           | Medium     | [Solution](/solutions/linked-list.md) |
| 16   | [Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/)                                           | Medium     | [Solution](/solutions/linked-list.md) |
| 17   | [Flatten Binary Tree To Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/)                   | Medium     | [Solution](/solutions/linked-list.md) |
| 18   | [Populating Next Right Pointers In Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/) | Medium     | [Solution](/solutions/linked-list.md) |
| 19   | [Copy List With Random Pointers](https://leetcode.com/problems/copy-list-with-random-pointer/)                            | Medium     | [Solution](/solutions/linked-list.md) |
| 20   | [Delete Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/)                               | Medium     | [Solution](/solutions/linked-list.md) |
| 21   | [Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list/)                                               | Medium     | [Solution](/solutions/linked-list.md) |
| 22   | [Swapping Nodes In A Linked List](https://leetcode.com/problems/swapping-nodes-in-a-linked-list/)                         | Medium     | [Solution](/solutions/linked-list.md) |
| 23   | [Merge Nodes In Between Zeros](https://leetcode.com/problems/merge-nodes-in-between-zeros/)                               | Medium     | [Solution](/solutions/linked-list.md) |
| 24   | [Reverse Nodes In K Group](https://leetcode.com/problems/reverse-nodes-in-k-group/)                                       | Hard       | [Solution](/solutions/linked-list.md) |
| 25   | [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)                                               | Hard       | [Solution](/solutions/linked-list.md) |

## 22. LIS

| S.No | Problem                                                                                                                                           | Difficulty | Solution                      |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------- |
| 1    | [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)                                                   | Medium     | [Solution](/solutions/lis.md) |
| 2    | [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence/)                                                   | Medium     | [Solution](/solutions/lis.md) |
| 3    | [Minimum Number of Removals To Make Mountain Array](https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/)             | Hard       | [Solution](/solutions/lis.md) |
| 4    | [Find The Longest Valid Obstacle Course At Each Position](https://leetcode.com/problems/find-the-longest-valid-obstacle-course-at-each-position/) | Hard       | [Solution](/solutions/lis.md) |

## 23. Manacher

| S.No | Problem                                                                                                                                                   | Difficulty | Solution                           |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------- |
| 1    | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/)                                                             | Medium     | [Solution](/solutions/manacher.md) |
| 2    | [Maximum Product of The Length of Two Palindromic Substrings](https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-substrings/) | Hard       | [Solution](/solutions/manacher.md) |

## 24. Matrix

| S.No | Problem                                                                                                             | Difficulty | Solution                         |
| ---- | ------------------------------------------------------------------------------------------------------------------- | ---------- | -------------------------------- |
| 1    | [Transpost Matrix](https://leetcode.com/problems/transpose-matrix/)                                                 | Easy       | [Solution](/solutions/matrix.md) |
| 2    | [Count Submatrices With All Ones](https://leetcode.com/problems/count-submatrices-with-all-ones/)                   | Medium     | [Solution](/solutions/matrix.md) |
| 3    | [Maximal Square](https://leetcode.com/problems/maximal-square/)                                                     | Medium     | [Solution](/solutions/matrix.md) |
| 4    | [Shortest Path In Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/)                     | Medium     | [Solution](/solutions/matrix.md) |
| 5    | [Sort The Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/)                             | Medium     | [Solution](/solutions/matrix.md) |
| 6    | [Count Square Submatrices With All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones/)     | Medium     | [Solution](/solutions/matrix.md) |
| 7    | [Number of Submatrices That Sum To Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/) | Hard       | [Solution](/solutions/matrix.md) |
| 8    | [Maximal Rectangle](https://leetcode.com/problems/maximal-rectangle/)                                               | Hard       | [Solution](/solutions/matrix.md) |

## 25. Merge Sort

| S.No | Problem                                                                                                       | Difficulty | Solution                             |
| ---- | ------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------ |
| 1    | [Sort List](https://leetcode.com/problems/sort-list/)                                                         | Medium     | [Solution](/solutions/merge-sort.md) |
| 2    | [Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/)     | Medium     | [Solution](/solutions/merge-sort.md) |
| 3    | [Count of Range Sum](https://leetcode.com/problems/count-of-range-sum/)                                       | Medium     | [Solution](/solutions/merge-sort.md) |
| 4    | [Reverse Pairs](https://leetcode.com/problems/reverse-pairs/)                                                 | Medium     | [Solution](/solutions/merge-sort.md) |
| 5    | [Number of Pairs Satisfying Inequality](https://leetcode.com/problems/number-of-pairs-satisfying-inequality/) | Medium     | [Solution](/solutions/merge-sort.md) |

## 26. Minimum Spanning Trees

| S.No | Problem                                                                                                                                                             | Difficulty | Solution                          |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------- |
| 1    | [Min Cost To Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points/)                                                                     | Medium     | [Solution](/solutions/kruskal.md) |
| 2    | [Find Critical And Pseudo Critical Edges in Minimum Spanning Tree](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/) | Medium     | [Solution](/solutions/kruskal.md) |

## 27. Prefix State Map

| S.No | Problem                                                                                                                                                   | Difficulty | Solution                                   |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------ |
| 1    | [Contiguous Array](https://leetcode.com/problems/contiguous-array/)                                                                                       | Medium     | [Solution](/solutions/prefix-state-map.md) |
| 2    | [Find The Longest Substring Containing Vowels In Even Counts](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/) | Medium     | [Solution](/solutions/prefix-state-map.md) |
| 3    | [Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring/)                                                           | Medium     | [Solution](/solutions/prefix-state-map.md) |
| 4    | [Number of Wonderful Substrings](https://leetcode.com/problems/number-of-wonderful-substrings/submissions/)                                               | Medium     | [Solution](/solutions/prefix-state-map.md) |

## 28. Queries

| S.No | Problem                                                                                                                   | Difficulty | Solution                          |
| ---- | ------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------- |
| 1    | [Most Beautiful Item For Each Query](https://leetcode.com/problems/most-beautiful-item-for-each-query/)                   | Medium     | [Solution](/solutions/queries.md) |
| 2    | [Queries On Number of Points Inside A Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/) | Medium     | [Solution](/solutions/queries.md) |
| 3    | [Range Frequency Queries](https://leetcode.com/problems/range-frequency-queries/)                                         | Medium     | [Solution](/solutions/queries.md) |
| 4    | [XOR Queries of a Subarray](https://leetcode.com/problems/xor-queries-of-a-subarray/)                                     | Medium     | [Solution](/solutions/queries.md) |
| 5    | [Queries On A Permutation With Key](https://leetcode.com/problems/queries-on-a-permutation-with-key/)                     | Medium     | [Solution](/solutions/queries.md) |
| 6    | [Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries/)                                               | Medium     | [Solution](/solutions/queries.md) |
| 7    | [Minimum Absolute Difference Queries](https://leetcode.com/problems/minimum-absolute-difference-queries/)                 | Medium     | [Solution](/solutions/queries.md) |
| 8    | [Maximum Genetic Difference Query](https://leetcode.com/problems/maximum-genetic-difference-query/)                       | Hard       | [Solution](/solutions/queries.md) |

## 29. Rolling Hash

| S.No | Problem                                                                                                     | Difficulty | Solution                                                                              |
| ---- | ----------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/)                             | Medium     | [Solution](/solutions/rolling-hash/repeated-dna-sequences.md)                         |
| 2    | [Shortest Palindrome](https://leetcode.com/problems/shortest-palindrome/)                                   | Medium     | [Solution](/solutions/rolling-hash/shortest-palindrome.md)                            |
| 3    | [Longest Duplicate Substring](https://leetcode.com/problems/longest-duplicate-substring/)                   | Medium     | [Solution](/solutions/rolling-hash/longest-duplicate-substring.md)                    |
| 4    | [Distinct Echo Substrings](https://leetcode.com/problems/distinct-echo-substrings/)                         | Medium     | [Solution](/solutions/rolling-hash/distinct-echo-substrings.md)                       |
| 5    | [K Divisible Elements Subarrays](https://leetcode.com/problems/k-divisible-elements-subarrays/)             | Medium     | [Solution](/solutions/rolling-hash/k-divisible-elements-subarray.md)                  |
| 6    | [Sum of Scores of Built Strings](https://leetcode.com/problems/sum-of-scores-of-built-strings/)             | Hard       | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 7    | [Find Substring With Given Hash Value](https://leetcode.com/problems/find-substring-with-given-hash-value/) | Hard       | [Solution](/solutions/rolling-hash/find-substring-with-given-hash-value.md)           |
| 8    | [Longest Common Subpath](https://leetcode.com/problems/longest-common-subpath/)                             | Hard       | [Solution](/solutions/rolling-hash/longest-common-subpath.md)                         |

## 30. Segment Tree

| S.No | Problem                                                                                                | Difficulty | Solution                               |
| ---- | ------------------------------------------------------------------------------------------------------ | ---------- | -------------------------------------- |
| 1    | [Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries/)  | Medium     | [Solution](/solutions/segment-tree.md) |
| 2    | [Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/)                    | Medium     | [Solution](/solutions/segment-tree.md) |
| 3    | [Longest Increasing Subseqence - II](https://leetcode.com/problems/longest-increasing-subsequence-ii/) | Medium     | [Solution](/solutions/segment-tree.md) |
| 4    | [Shifting Letters - II](https://leetcode.com/problems/shifting-letters-ii/)                            | Medium     | [Solution](/solutions/segment-tree.md) |
| 5    | [Falling Squares](https://leetcode.com/problems/falling-squares/)                                      | Hard       | [Solution](/solutions/segment-tree.md) |

## 31. Sets

| S.No | Problem                                                                                                             | Difficulty | Solution                       |
| ---- | ------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------ |
| 1    | [Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/) | Medium     | [Solution](/solutions/sets.md) |

## 32. Sieve of Eratosthenes

| S.No | Problem                                                       | Difficulty | Solution                                     |
| ---- | ------------------------------------------------------------- | ---------- | -------------------------------------------- |
| 1    | [Count Primes](https://leetcode.com/problems/count-primes/)   | Medium     | [Solution](/solutions/sieve-eratosthenes.md) |
| 2    | [Four Divisors](https://leetcode.com/problems/four-divisors/) | Medium     | [Solution](/solutions/sieve-eratosthenes.md) |

## 33. Sliding Window

| S.No | Problem                                                                                                                         | Difficulty | Solution                                                                  |
| ---- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------- |
| 1    | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 2    | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)                                           | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 3    | [Number of Smooth Descent Periods of Stock](https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/)         | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 4    | [Maximize The Confusion of An Exam](https://leetcode.com/problems/maximize-the-confusion-of-an-exam/)                           | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 5    | [Frequency of Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/)                     | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 6    | [Max Consecutive Ones - III](https://leetcode.com/problems/max-consecutive-ones-iii/)                                           | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 7    | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/)               | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 8    | [Permutation In String](https://leetcode.com/problems/permutation-in-string/)                                                   | Medium     | [Solution](/solutions/sliding-window.md)                                  |
| 9    | [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)                                             | Hard       | [Solution](/solutions/sliding-window.md)                                  |
| 10   | [Substring With Concatenation Of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/)           | Hard       | [Solution](/solutions/sliding-window.md)                                  |
| 11   | [Count Subarrays With Fixed Count](https://leetcode.com/problems/count-subarrays-with-fixed-bounds/)                            | Hard       | [Solution](/solutions/sliding-window/count-subarrays-with-fixed-count.md) |

## 34. Stack

| S.No | Problem                                                                                                                                                     | Difficulty | Solution                        |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------- |
| 1    | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)                                                                                       | Easy       | [Solution](/solutions/stack.md) |
| 2    | [Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/)                                                                 | Easy       | [Solution](/solutions/stack.md) |
| 3    | [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/)                                                                             | Easy       | [Solution](/solutions/stack.md) |
| 4    | [Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/)                                                                         | Easy       | [Solution](/solutions/stack.md) |
| 5    | [Min Stack](https://leetcode.com/problems/min-stack/)                                                                                                       | Medium     | [Solution](/solutions/stack.md) |
| 6    | [Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii/)                                                                           | Medium     | [Solution](/solutions/stack.md) |
| 7    | [132 Patterns](https://leetcode.com/problems/132-pattern/)                                                                                                  | Medium     | [Solution](/solutions/stack.md) |
| 8    | [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/)                                                                                     | Medium     | [Solution](/solutions/stack.md) |
| 9    | [Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/)                                                                                 | Medium     | [Solution](/solutions/stack.md) |
| 10   | [Validate Stack Sequences](https://leetcode.com/problems/validate-stack-sequences/)                                                                         | Medium     | [Solution](/solutions/stack.md) |
| 11   | [Next Greater Node In Linked List](https://leetcode.com/problems/next-greater-node-in-linked-list/)                                                         | Medium     | [Solution](/solutions/stack.md) |
| 12   | [The Number of Weak Characters In The Game](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/)                                       | Medium     | [Solution](/solutions/stack.md) |
| 13   | [Construct Smallest Number From DI String](https://leetcode.com/problems/construct-smallest-number-from-di-string/)                                         | Medium     | [Solution](/solutions/stack.md) |
| 14   | [Maximum Frequency Stack](https://leetcode.com/problems/maximum-frequency-stack/)                                                                           | Medium     | [Solution](/solutions/stack.md) |
| 15   | [Basic Calculator](https://leetcode.com/problems/basic-calculator/)                                                                                         | Medium     | [Solution](/solutions/stack.md) |
| 16   | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/)                                                                       | Medium     | [Solution](/solutions/stack.md) |
| 17   | [Using A Robot To Print The Lexicographically Smallest String](https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/) | Medium     | [Solution](/solutions/stack.md) |

## 35. Stringstream

| S.No | Problem                                                                                       | Difficulty | Solution                               |
| ---- | --------------------------------------------------------------------------------------------- | ---------- | -------------------------------------- |
| 1    | [Reverse Words In A String-III](https://leetcode.com/problems/reverse-words-in-a-string-iii/) | Medium     | [Solution](/solutions/stringstream.md) |
| 2    | [Find Duplicate File In System](https://leetcode.com/problems/find-duplicate-file-in-system/) | Medium     | [Solution](/solutions/stringstream.md) |
| 3    | [Apply Discount To Prices](https://leetcode.com/problems/apply-discount-to-prices/)           | Medium     | [Solution](/solutions/stringstream.md) |

## 36. Sum of First N Natural Numbers

| S.No | Problem                                                                                                                   | Difficulty | Solution                                                 |
| ---- | ------------------------------------------------------------------------------------------------------------------------- | ---------- | -------------------------------------------------------- |
| 1    | [Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings/description/) | Medium     | [Solution](/solutions/sum-of-first-n-natural-numbers.md) |
| 2    | [Number of Substrings With Only 1s](https://leetcode.com/problems/number-of-substrings-with-only-1s/description/)         | Medium     | [Solution](/solutions/sum-of-first-n-natural-numbers.md) |

## 37. Topological Sort

| S.No | Problem                                                                                                                                 | Difficulty | Solution                                   |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------ |
| 1    | [Course Schedule](https://leetcode.com/problems/course-schedule/)                                                                       | Medium     | [Solution](/solutions/topological-sort.md) |
| 2    | [Course Schedule II](https://leetcode.com/problems/course-schedule-ii/)                                                                 | Medium     | [Solution](/solutions/topological-sort.md) |
| 3    | [Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/)                                                             | Medium     | [Solution](/solutions/topological-sort.md) |
| 4    | [Longest Incresing Path In A Matrix](https://leetcode.com/problems/longest-increasing-path-in-a-matrix/)                                | Medium     | [Solution](/solutions/topological-sort.md) |
| 5    | [All Ancestors of a Node In Directed Acyclic Graph](https://leetcode.com/problems/all-ancestors-of-a-node-in-a-directed-acyclic-graph/) | Medium     | [Solution](/solutions/topological-sort.md) |
| 6    | [Number of Ways To Arrive At Destination](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/)                       | Medium     | [Solution](/solutions/topological-sort.md) |
| 7    | [Parallel Courses III](https://leetcode.com/problems/parallel-courses-iii/)                                                             | Hard       | [Solution](/solutions/topological-sort.md) |
| 8    | [Build A Matrix With Conditions](https://leetcode.com/problems/build-a-matrix-with-conditions/)                                         | Hard       | [Solution](/solutions/topological-sort.md) |

## 38. Trie

| S.No | Problem                                                                                                         | Difficulty | Solution                                                         |
| ---- | --------------------------------------------------------------------------------------------------------------- | ---------- | ---------------------------------------------------------------- |
| 1    | [Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)                       | Medium     | [Solution](/solutions/trie/implement-trie.md)                    |
| 2    | [Search Suggestions System](https://leetcode.com/problems/search-suggestions-system/)                           | Medium     | [Solution](/solutions/trie/search-suggestions-system.md)         |
| 3    | [Maximum XOR of Two Numbers In An Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) | Medium     | [Solution](/solutions/trie/maximum-xor-of-two-numbers.md)        |
| 4    | [K Divisible Elements Subarray](https://leetcode.com/problems/k-divisible-elements-subarrays/)                  | Medium     | [Solution](/solutions/trie/k-divisible-elements-subarrays.md)    |
| 5    | [Maximum Genetic Difference Query](https://leetcode.com/problems/maximum-genetic-difference-query/)             | Hard       | [Solution](/solutions/trie//maximum-genetic-difference-query.md) |
| 6    | [Concatenated Words](https://leetcode.com/problems/concatenated-words/)                                         | Hard       | [Solution](/solutions/trie/concatenated-words.md)                |
| 7    | [Palindrome Pairs](https://leetcode.com/problems/palindrome-pairs/)                                             | Hard       | [Solution](/solutions/trie/palindrome-pairs.md)                  |
| 8    | [Sum of Prefix Scores of Strings](https://leetcode.com/problems/sum-of-prefix-scores-of-strings/)               | Hard       | [Solution](/solutions/trie/sum-of-prefix-scores-of-strings.md)   |

## 39. Two Dimensional Plane

| S.No | Problem                                                                                                                   | Difficulty | Solution                                                                              |
| ---- | ------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Max Points On A Line](https://leetcode.com/problems/max-points-on-a-line/)                                               | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Min Cost To Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points/)                           | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 3    | [Queries On Number of Points Inside A Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 4    | [Detonate The Maximum Bombs](https://leetcode.com/problems/detonate-the-maximum-bombs/)                                   | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 40. Two Pointer

| S.No | Problem                                                                                                      | Difficulty | Solution                                                                              |
| ---- | ------------------------------------------------------------------------------------------------------------ | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Two Sum](https://leetcode.com/problems/two-sum/)                                                            | Easy       | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Remove Duplicates From Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/)      | Easy       | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 3    | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)                                        | Easy       | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 4    | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)                                            | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 5    | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/)                        | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 6    | [3Sum](https://leetcode.com/problems/3sum/)                                                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 7    | [3Sum Closest](https://leetcode.com/problems/3sum-closest/)                                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 8    | [Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)          | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 9    | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)                                    | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 10   | [Sort Colors](https://leetcode.com/problems/sort-colors/)                                                    | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 11   | [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)                          | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 12   | [Linked List Cycle-II](https://leetcode.com/problems/linked-list-cycle-ii/)                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 13   | [Reorder List](https://leetcode.com/problems/reorder-list/)                                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 14   | [Sort List](https://leetcode.com/problems/sort-list/)                                                        | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 15   | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/)                          | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 16   | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |

## 41. Union Find

| S.No | Problem                                                                                                    | Difficulty | Solution                                                                              |
| ---- | ---------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------- |
| 1    | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)                | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 2    | [Number of Islands](https://leetcode.com/problems/number-of-islands/)                                      | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 3    | [Number of Provinces](https://leetcode.com/problems/number-of-provinces/)                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 4    | [Redundant Connections](https://leetcode.com/problems/redundant-connection/)                               | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 5    | [Max Area of Island](https://leetcode.com/problems/max-area-of-island/)                                    | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 6    | [Is Graph Bipartite ?](https://leetcode.com/problems/is-graph-bipartite/)                                  | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 7    | [Satifiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/) | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 8    | [Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps/)                    | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |
| 9    | [Number of Good Paths](https://leetcode.com/problems/number-of-good-paths/)                                | Medium     | [Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md) |


<p align="left"> <img src="https://komarev.com/ghpvc/?username=kiranpalsingh1806&label=Views&color=blue&style=plastic" alt="kiranpalsingh" /> </p>


================================================
FILE: markdown/code-2.md
================================================
## Heading here

```cpp

```

================================================
FILE: markdown/code.md
================================================
## Heading here

<details>
<summary> View Code </summary>

```cpp

```

</details>

================================================
FILE: random/Random.md
================================================
# LeetCode Problems

|Index|Problem|Topic|Solution|
|------|------|--------|------|
|1|[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|2|[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|3|[Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/)|Custom Comparator|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|4|[Min Cost To Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points/)|Kruskal Algorithm|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|5|[Power(X, n)](https://leetcode.com/problems/powx-n/)|Recursion|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|6|[Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/)|Tarjan's Algorithm|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|7|[Longest Increasing Path in Matrix](https://leetcode.com/problems/longest-increasing-path-in-a-matrix/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|8|[Valid Arrangement of Pairs](https://leetcode.com/problems/valid-arrangement-of-pairs/)|Euler Tour|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|9|[Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii/)|Stack|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|10|[Container With Most Water](https://leetcode.com/problems/container-with-most-water/)|Two Pointer|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|11|[Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)|Trie|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|12|[Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/)|Matrix|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|13|[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)|Sliding Window|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|14|[Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence/)|LIS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|15|[Target Sum](https://leetcode.com/problems/target-sum/)|Recursion, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|16|[Check if there is Valid Partition For The Array](https://leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/)|Recursion, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|17|[Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/)|Union Find|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|18|[Valid Sudoku](https://leetcode.com/problems/valid-sudoku/)|BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|19|[My Calendar I](https://leetcode.com/problems/my-calendar-i/)|Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|20|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)|Deque, Sliding Window|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|21|[Best Time To Buy and Sell Stock]()|Array, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|22|[Maximum Subarray]()|Kadane Algorithm|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|23|[Cracking The Safe]()|Euler Tour, Heirholzer Algorithm|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|24|[Find If Path Exists In Graph]()|Graphs, BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|25|[Next Greater Node In Linked List]()|Linked List, Stack|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|26|[Repeated Substring Pattern]()|String|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|27|[Search Suggestion System]()|Trie|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|28|[Merge K Sorted Lists]()|Heaps, Custom Comparator|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|29|[Daily Temperatures]()|Monotonous Stack|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|30|[Merge Intervals]()|Intervals|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|31|[Word Ladder]()|BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|32|[3 Sum]()|Two Pointer|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|33|[Flatten Binary Tree To Linked List]()|Linked List, Stacks|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|34|[Sum of Subarray Minimums]()|Monotonous Stack|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|35|[Median of Two Sorted Arrays]()|Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|36|[LRU Cache]()|Data Structure, Design|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|37|[Gas Station]()|Greedy, Prefix Sum|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|38|[Max Points On A Line]()|Slope Of Line|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|39|[Largest Rectangle In Histogram]()|Monotonic Stack|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|40|[Regular Expression Matching]()|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|41|[Minimum Deletions To Make Character Frequencies Unique](https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/)|Strings|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|42|[Jump Game II](https://leetcode.com/problems/jump-game-ii/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|43|[Count Good Nodes In Binary Tree](https://leetcode.com/problems/count-good-nodes-in-binary-tree/)|Binary Trees|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|44|[Unique Paths](https://leetcode.com/problems/unique-paths/)|DP, Grid|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|45|[Coin Change](https://leetcode.com/problems/coin-change/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|46|[Is Graph Bipartite ?](https://leetcode.com/problems/is-graph-bipartite/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|47|[Frequency of Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/)|Sliding Window|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|48|[Group Anagrams](https://leetcode.com/problems/group-anagrams/)|Sorting|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|49|[Satisfiability Of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/)|Union Find|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|50|[Range Sum BST](https://leetcode.com/problems/range-sum-of-bst/)|Binary Search Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|51|[Number of Islands](https://leetcode.com/problems/number-of-islands/)|DFS, BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|52|[Wildcard Matching](https://leetcode.com/problems/wildcard-matching/)|Strings, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|53|[Min Stack](https://leetcode.com/problems/min-stack/)|Data Structure|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|54|[Permutations](https://leetcode.com/problems/permutations/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|55|[Combinations](https://leetcode.com/problems/combinations/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|56|[Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/)|BST|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|57|[Peak Index In A Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/)|Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|58|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|59|[Find Minimum In Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/)|Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|60|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)|BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|61|[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)|Sliding Window|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|62|[Combination Sum](https://leetcode.com/problems/combination-sum/)|Backtracking, DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|63|[N-Queens](https://leetcode.com/problems/n-queens/)|Grid, Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|64|[Subsets](https://leetcode.com/problems/subsets/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|65|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|66|[House Robber II](https://leetcode.com/problems/house-robber-ii/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|67|[Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/)|DP, Subset Sum|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|68|[Number of Submatrices That Sum To Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/)|Grid, Prefix Sum 2D|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|69|[Shortest Path In Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/)|BFS, Shortest Path|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|70|[Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)|BST, Recursion|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|71|[Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/)|Linked List|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|72|[Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|73|[Find Missing Positive](https://leetcode.com/problems/first-missing-positive/)|Implementation|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|74|[Edit Distance](https://leetcode.com/problems/edit-distance/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|75|[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|76|[Shifting Letters II](https://leetcode.com/problems/shifting-letters-ii/)|Line Sweep, Fenwick Tree, Segment Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|77|[Build a Matrix With Conditions](https://leetcode.com/problems/build-a-matrix-with-conditions/)|Topological Sort|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|78|[Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-bst/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|79|[Pacific Atlantic Water Flow](https://leetcode.com/problems/pacific-atlantic-water-flow/)|DFS, Grid|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|80|[Delete And Earn](https://leetcode.com/problems/delete-and-earn/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|81|[Permutations II](https://leetcode.com/problems/permutations-ii/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|82|[Combination Sum II](https://leetcode.com/problems/combination-sum-ii/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|83|[Non Overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/)|Intervals|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|84|[Best Time To Buy and Sell Stocks With Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/)|Recursion, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|85|[Maximum XOR of Two Numbers In An Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/)|Bitmasks, Trie|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|86|[Implement Queue Using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/)|Data Structure|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|87|[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)|Sliding Window|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|88|[Number of Visible People In A Queue](https://leetcode.com/problems/number-of-visible-people-in-a-queue/)|Mono-Deque, Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|89|[Describe The Painting](https://leetcode.com/problems/describe-the-painting/)|Line Sweep|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|90|[Flood Fill](https://leetcode.com/problems/flood-fill/)|Grid, BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|91|[Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning/)|Backtracking|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|92|[Path With Maximum Gold](https://leetcode.com/problems/path-with-maximum-gold/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|93|[Counting Bits](https://leetcode.com/problems/counting-bits/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|94|[Word Break](https://leetcode.com/problems/word-break/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|95|[Find Median From Data Stream](https://leetcode.com/problems/find-median-from-data-stream/)|Heaps|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|96|[Single Threaded CPU](https://leetcode.com/problems/single-threaded-cpu/)|Greedy Scheduling|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|97|[Contiguous Array](https://leetcode.com/problems/contiguous-array/)|Prefix State Map|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|98|[Falling Squares](https://leetcode.com/problems/falling-squares/)|Segment Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|99|[Minimum XOR Sum of Two Arrays](https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/)|Bitmasks, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|100|[Maximum Profit In Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)|Binary Search, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|101|[Find Minimum Time To Finish All Jobs](https://leetcode.com/problems/find-minimum-time-to-finish-all-jobs/)|Bitmasks, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|102|[Course Schedule](https://leetcode.com/problems/course-schedule/)|Topological Sort|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|103|[Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/)|Tree Ring Order Traversal|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|104|[Russian Doll Envelopes](https://leetcode.com/problems/russian-doll-envelopes/)|LIS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|105|[Maximum AND Sum of Array](https://leetcode.com/problems/maximum-and-sum-of-array/)|Bitmasks, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|106|[Maximum Number of Robots Within Budget](https://leetcode.com/problems/maximum-number-of-robots-within-budget/)|Sliding Window, Binary Search, Sparse Table|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|107|[Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring/)|Prefix State Map|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|108|[Maximum Rows Covered By Columns](https://leetcode.com/problems/maximum-rows-covered-by-columns/)|Bitmasks|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|109|[Create Sorted Array Through Instructions](https://leetcode.com/problems/create-sorted-array-through-instructions/)|Binary Indexed Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|110|[Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam/)|Bitmasks|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|111|[Number of Ways To Reach A Position After Exactly K Steps](https://leetcode.com/problems/number-of-ways-to-reach-a-position-after-exactly-k-steps/)|Recursion, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|112|[Find The Longest Substring Containing Vowels In Even Counts](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/)|Prefix State Map|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|113|[Maximum Earnings From Taxi](https://leetcode.com/problems/maximum-earnings-from-taxi/)|DP, Binary Search|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|114|[Vertical Order Traversal Of A Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|115|[Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|116|[Count Primes](https://leetcode.com/problems/count-primes/)|Sieve of Eratosthenes|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|117|[Find The Shortest Superstring](https://leetcode.com/problems/find-the-shortest-superstring/)|Bitmasks, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|118|[Sum Root To Leaf Nodes](https://leetcode.com/problems/sum-root-to-leaf-numbers/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|119|[Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|120|[Count Number of Maximum Bitwise Or Subsets](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/)|Bitmasks|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|121|[Jump Game III](https://leetcode.com/problems/jump-game-iii/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|122|[Operations On Tree](https://leetcode.com/problems/operations-on-tree/)|Trees|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|123|[Minimum Operations To Convert Number](https://leetcode.com/problems/minimum-operations-to-convert-number/)|BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|124|[Egg Drop With 2 Eggs And N Floors](https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors/)|DP, Maths|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|125|[Time Needed To Inform All Employees](https://leetcode.com/problems/time-needed-to-inform-all-employees/)|BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|126|[Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/)|Design|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|127|[Shortest Bridge](https://leetcode.com/problems/shortest-bridge/)|DFS, BFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|128|[Flip String To Monotone Increasing](https://leetcode.com/problems/flip-string-to-monotone-increasing/)|String|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|129|[Longest Increasing Subsequence - II](https://leetcode.com/problems/longest-increasing-subsequence-ii/)|Segment Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|130|[Solving Questions With Brainpower](https://leetcode.com/problems/solving-questions-with-brainpower/)|DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|131|[Detonate The Maximum Bombs](https://leetcode.com/problems/detonate-the-maximum-bombs/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|132|[Fair Distribution of Cookies](https://leetcode.com/problems/fair-distribution-of-cookies/)|Bitmasks, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|133|[Minimum Cost To Reach Destination In Time](https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/)|Dijkstra|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|134|[Longest Substring Of One Repeating Character](https://leetcode.com/problems/longest-substring-of-one-repeating-character/)|Segment Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|135|[Predict The Winner](https://leetcode.com/problems/predict-the-winner/)|Recursion, DP|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|136|[Path With Minimum Effort](https://leetcode.com/problems/path-with-minimum-effort/)|Dijkstra|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|137|[Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/)|Bellman Ford, Dijkstra|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|138|[Minimum Cost To Make at Least One Valid Path In a Grid](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/)|BFS + DP, Dijkstra|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|139|[Frog Jump](https://leetcode.com/problems/frog-jump/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|140|[Find Eventual Safe State](https://leetcode.com/problems/find-eventual-safe-states/)|Topological Sort|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|141|[Number of Ways To Arrive At Destination](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/)|Dijkstra|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|142|[Sort List](https://leetcode.com/problems/sort-list/)|Merge Sort, Quick Sort|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|143|[Frog Position After T Seconds](https://leetcode.com/problems/frog-position-after-t-seconds/)|DFS|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|144|[Longest Zigzag Path In A Binary Tree](https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|145|[Balance A Binary Search Tree](https://leetcode.com/problems/balance-a-binary-search-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|146|[Linked List In Binary Tree](https://leetcode.com/problems/linked-list-in-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|147|[Find Substring With Given Hash Value](https://leetcode.com/problems/find-substring-with-given-hash-value/)|Rolling Hash|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|148|[Distinct Echo Substrings](https://leetcode.com/problems/distinct-echo-substrings/)|Rolling Hash|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|149|[Longest Duplicate Substring](https://leetcode.com/problems/longest-duplicate-substring/)|Rolling Hash|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|150|[Distribute Coins In Binary Tree](https://leetcode.com/problems/distribute-coins-in-binary-tree/)|Binary Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|151|[Range Sum Query Mutable](https://leetcode.com/problems/range-sum-query-mutable/)|Segment Tree|[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|152|[Shortest Palindrome](https://leetcode.com/problems/shortest-palindrome/)||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|153|[Maximum Number of Events That Can Be Attended](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/)||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|154|[Maximum Product of The Length of Two Palindromic Substrings](https://leetcode.com/problems/maximum-product-of-the-length-of-two-palindromic-substrings/)||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|155|[Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/)||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|156|[K Divisible Elements Subarray](https://leetcode.com/problems/k-divisible-elements-subarrays/)||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|
|157|[]()||[Solution](https://github.com/kiranpalsingh1806/awesome-dsa/blob/master/SOLUTIONS.md)|

================================================
FILE: random/SOLUTIONS.md
================================================
# Table of Contents
- [Table of Contents](#table-of-contents)
  - [1. Longest Increasing Subsequence](#1-longest-increasing-subsequence)
  - [2. Generate Parentheses](#2-generate-parentheses)
  - [3. Sort Array By Parity](#3-sort-array-by-parity)
  - [4. Min Cost To Connect All Points](#4-min-cost-to-connect-all-points)
  - [5. Power(x, n)](#5-powerx-n)
  - [6. Critical Connections In A Network](#6-critical-connections-in-a-network)
  - [7. Longest Increasing Path In A Matrix](#7-longest-increasing-path-in-a-matrix)
  - [8. Valid Arrangement of Pairs](#8-valid-arrangement-of-pairs)
  - [9. Next Greater Element II](#9-next-greater-element-ii)
  - [10. Container With Most Water](#10-container-with-most-water)
  - [11. Implement Trie (Prefix Tree)](#11-implement-trie-prefix-tree)
  - [12. Sort The Matrix Diagonally](#12-sort-the-matrix-diagonally)
  - [13. Minimum Window Substring](#13-minimum-window-substring)
  - [14. Increasing Triplet Subsequence](#14-increasing-triplet-subsequence)
  - [15. Target Sum](#15-target-sum)
  - [16. Check If There Is A Valid Partition For The Array](#16-check-if-there-is-a-valid-partition-for-the-array)
  - [17. Longest Consecutive Sequence](#17-longest-consecutive-sequence)
  - [18. Valid Sudoku](#18-valid-sudoku)
  - [19. My Calendar I](#19-my-calendar-i)
  - [20. Sliding Window Maximum](#20-sliding-window-maximum)
  - [21. Best Time To Buy and Sell Stock](#21-best-time-to-buy-and-sell-stock)
  - [22. Maximum Subarray](#22-maximum-subarray)
  - [23. Cracking The Safe](#23-cracking-the-safe)
  - [24. Find If Path Exists In Graph](#24-find-if-path-exists-in-graph)
  - [25. Next Greater Node In Linked List](#25-next-greater-node-in-linked-list)
  - [26. Repeated Substring Pattern](#26-repeated-substring-pattern)
  - [27. Search Suggestion System](#27-search-suggestion-system)
  - [28. Merge K Sorted Lists](#28-merge-k-sorted-lists)
  - [29. Daily Temperatures](#29-daily-temperatures)
  - [30. Merge Intervals](#30-merge-intervals)
  - [31. Word Ladder](#31-word-ladder)
  - [32. 3Sum](#32-3sum)
  - [33. Flatten Binary Tree To Linked List](#33-flatten-binary-tree-to-linked-list)
  - [34. Sum of Subarray Minimums](#34-sum-of-subarray-minimums)
  - [35. Median of Two Sorted Arrays](#35-median-of-two-sorted-arrays)
  - [36. LRU Cache](#36-lru-cache)
  - [37. Gas Station](#37-gas-station)
  - [38. Max Points On A Line](#38-max-points-on-a-line)
  - [39. Largest Rectangle In Histogram](#39-largest-rectangle-in-histogram)
  - [40. Regular Expression Matching](#40-regular-expression-matching)
  - [41. Minimum Deletions To Make Character Frequencies Unique](#41-minimum-deletions-to-make-character-frequencies-unique)
  - [42. Jump Game II](#42-jump-game-ii)
  - [43. Count Good Nodes In Binary Tree](#43-count-good-nodes-in-binary-tree)
  - [44. Unique Paths](#44-unique-paths)
  - [45. Coin Change](#45-coin-change)
  - [46. Is Graph Bipartite ?](#46-is-graph-bipartite-)
  - [47. Frequency of Most Frequent Elements](#47-frequency-of-most-frequent-elements)
  - [48. Group Anagrams](#48-group-anagrams)
  - [49. Satisfiability of Equality Equations](#49-satisfiability-of-equality-equations)
  - [50. Range Sum BST](#50-range-sum-bst)
  - [51. Number of Islands](#51-number-of-islands)
  - [52. Wildcard Matching](#52-wildcard-matching)
  - [53. Min Stack](#53-min-stack)
  - [54. Permutations](#54-permutations)
  - [55. Combinations](#55-combinations)
  - [56. Diameter of Binary Tree](#56-diameter-of-binary-tree)
  - [57. Peak Index In Mountain Array](#57-peak-index-in-mountain-array)
  - [58. Maximum Depth of Binary Tree](#58-maximum-depth-of-binary-tree)
  - [59. Find Minimum In Rotated Sorted Array](#59-find-minimum-in-rotated-sorted-array)
  - [60. Binary Tree Zigzag Level Order Traversal](#60-binary-tree-zigzag-level-order-traversal)
  - [61. Longest Substring Without Repeating Characters](#61-longest-substring-without-repeating-characters)
  - [62. Combination Sum](#62-combination-sum)
  - [63. N-Queens](#63-n-queens)
  - [64. Subsets](#64-subsets)
  - [65. Pascal's Triangle](#65-pascals-triangle)
  - [66. House Robber II](#66-house-robber-ii)
  - [67. Partition Equal Subset Sum](#67-partition-equal-subset-sum)
  - [68. Number of Submatrices That Sum To Target](#68-number-of-submatrices-that-sum-to-target)
  - [69. Shortest Path in Binary Matrix](#69-shortest-path-in-binary-matrix)
  - [70.Validate Binary Search Tree](#70validate-binary-search-tree)
  - [71. Reverse Nodes in k-Group](#71-reverse-nodes-in-k-group)
  - [72. Trapping Rain Water](#72-trapping-rain-water)
  - [73. Find Missing Positive](#73-find-missing-positive)
  - [74. Edit Distance](#74-edit-distance)
  - [75. Climbing Stairs](#75-climbing-stairs)
  - [76. Shifting Letters II](#76-shifting-letters-ii)
  - [77. Build A Matrix With Conditions](#77-build-a-matrix-with-conditions)
  - [78. Serialize and Deserialize Binary Tree](#78-serialize-and-deserialize-binary-tree)
  - [79. Pacific Atlantic Water Flow](#79-pacific-atlantic-water-flow)
  - [80. Delete and Earn](#80-delete-and-earn)
  - [81. Permutations II](#81-permutations-ii)
  - [82. Combination Sum II](#82-combination-sum-ii)
  - [83. Non Overlapping Intervals](#83-non-overlapping-intervals)
  - [84. Best Time To Buy and Sell Stocks With Cooldown](#84-best-time-to-buy-and-sell-stocks-with-cooldown)
  - [85. Maximum XOR of Two Numbers In An Array](#85-maximum-xor-of-two-numbers-in-an-array)
  - [86. Implement Queue Using Stacks](#86-implement-queue-using-stacks)
  - [87. Minimum Size Subarray Sum](#87-minimum-size-subarray-sum)
  - [88. Number of Visible People In A Queue](#88-number-of-visible-people-in-a-queue)
  - [89. Describe The Painting](#89-describe-the-painting)
  - [90. Flood Fill](#90-flood-fill)
  - [91. Palindrome Partitioning](#91-palindrome-partitioning)
  - [92. Path With Maximum Gold](#92-path-with-maximum-gold)
  - [93. Counting Bits](#93-counting-bits)
  - [94. Word Break](#94-word-break)
  - [95. Find Median From Data Stream](#95-find-median-from-data-stream)
  - [96. Single Threaded CPU](#96-single-threaded-cpu)
  - [97. Contiguous Array](#97-contiguous-array)
  - [98. Falling Squares](#98-falling-squares)
  - [99. Minimum XOR Sum of Two Arrays](#99-minimum-xor-sum-of-two-arrays)
  - [100. Maximum Profit In Job Scheduling](#100-maximum-profit-in-job-scheduling)
  - [101. Find Minimum Time To Finish All Jobs](#101-find-minimum-time-to-finish-all-jobs)
  - [102. Course Schedule](#102-course-schedule)
  - [103. Minimum Height Trees](#103-minimum-height-trees)
  - [104. Russian Doll Envelopes](#104-russian-doll-envelopes)
  - [105. Maximum AND Sum of Array](#105-maximum-and-sum-of-array)
  - [106. Maximum Number of Robots Within Budget](#106-maximum-number-of-robots-within-budget)
  - [107. Find Longest Awesome Substring](#107-find-longest-awesome-substring)
  - [108. Maximum Rows Covered By Columns](#108-maximum-rows-covered-by-columns)
  - [109. Create Sorted Array Through Instructions](#109-create-sorted-array-through-instructions)
  - [110. Maximum Students Taking Exam](#110-maximum-students-taking-exam)
  - [111. Number of Ways To Reach A Position After Exactly K Steps](#111-number-of-ways-to-reach-a-position-after-exactly-k-steps)
  - [112. Find The Longest Substring Containing Vowels In Even Counts](#112-find-the-longest-substring-containing-vowels-in-even-counts)
  - [113. Maximum Earnings From Taxi](#113-maximum-earnings-from-taxi)
  - [114. Vertical Order Traversal Of A Binary Tree](#114-vertical-order-traversal-of-a-binary-tree)
  - [115. Invert Binary Tree](#115-invert-binary-tree)
  - [116. Count Primes](#116-count-primes)
  - [117. Find The Shortest Superstring](#117-find-the-shortest-superstring)
  - [118. Sum Root To Leaf Nodes](#118-sum-root-to-leaf-nodes)
  - [119. Longest Common Subsequence](#119-longest-common-subsequence)
  - [120. Count Number of Maximum Bitwise Or Subsets](#120-count-number-of-maximum-bitwise-or-subsets)
  - [121. Jump Game III](#121-jump-game-iii)
  - [122. Operations on Tree](#122-operations-on-tree)
  - [123. Minimum Operations To Convert Number](#123-minimum-operations-to-convert-number)
  - [124. Egg Drop With 2 Eggs and N Floors](#124-egg-drop-with-2-eggs-and-n-floors)
  - [125. Time Needed To Inform All Employees](#125-time-needed-to-inform-all-employees)
  - [126. Time Based Key-Value Store](#126-time-based-key-value-store)
  - [127. Shortest Bridge](#127-shortest-bridge)
  - [128. Flip String To Monotone Increasing](#128-flip-string-to-monotone-increasing)
  - [129. Longest Increasing Subsequence - II](#129-longest-increasing-subsequence---ii)
  - [130. Solving Questions With Brainpower](#130-solving-questions-with-brainpower)
  - [131. Detonate The Maximum Bombs](#131-detonate-the-maximum-bombs)
  - [132. Fair Distribution of Cookies](#132-fair-distribution-of-cookies)
  - [133. Minimum Cost To Reach Destination In Time](#133-minimum-cost-to-reach-destination-in-time)
  - [134. Longest Substring of One Repeating Character](#134-longest-substring-of-one-repeating-character)
  - [135. Predict The Winner](#135-predict-the-winner)
  - [136. Path With Minimum Effort](#136-path-with-minimum-effort)
  - [137. Cheapest Flights Within K Stops](#137-cheapest-flights-within-k-stops)
  - [138. Minimum Cost To Make at Least One Valid Path in Grid](#138-minimum-cost-to-make-at-least-one-valid-path-in-grid)
  - [139. Frog Jump](#139-frog-jump)
  - [140. Find Eventual Safe State](#140-find-eventual-safe-state)
  - [141. No of Ways To Arrive At Destination](#141-no-of-ways-to-arrive-at-destination)
  - [142. Sort List](#142-sort-list)
  - [143. Frog Position After T Seconds](#143-frog-position-after-t-seconds)
  - [144. Longest Zigzag Path In A Binary Tree](#144-longest-zigzag-path-in-a-binary-tree)
  - [145. Balance A Binary Seach Tree](#145-balance-a-binary-seach-tree)
  - [146. Linked List in Binary Tree](#146-linked-list-in-binary-tree)
  - [147. Find Substring With Given Hash Value](#147-find-substring-with-given-hash-value)
  - [148. Distinct Echo Substrings](#148-distinct-echo-substrings)
  - [149. Longest Duplicate Substring](#149-longest-duplicate-substring)
  - [150. Distribute Coins In Binary Tree](#150-distribute-coins-in-binary-tree)
  - [151. Range Sum Query - Mutable](#151-range-sum-query---mutable)
  - [152. Shortest Palindrome](#152-shortest-palindrome)
  - [153. Maximum Number of Events That Can Be Attended](#153-maximum-number-of-events-that-can-be-attended)
  - [154. Maximum Product of The Length of Two Palindromic Substrings](#154-maximum-product-of-the-length-of-two-palindromic-substrings)
  - [155. Repeated DNA Sequences](#155-repeated-dna-sequences)
  - [156. K Divisible Elements Subarray](#156-k-divisible-elements-subarray)
  - [157. Problem Name](#157-problem-name)

## 1. Longest Increasing Subsequence

<details>
<summary> Solution - DP </summary>

```cpp
int lengthOfLIS(vector<int>& nums) {
    int N = nums.size();
    
    vector<int> dp;
    
    for(int i = 0; i < N; i++) {
        
        auto it = lower_bound(dp.begin(), dp.end(), nums[i]);
        
        if(it != dp.end()) {
            *it = nums[i];
        } else {
            dp.push_back(nums[i]);
        }
    }
    
    return dp.size();
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 2. Generate Parentheses

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    vector<string> ans;
    
    void backtracking(string &temp, int leftCnt, int rightCnt) {
        
        // We found a valid parentheses.
        if(leftCnt == 0 && rightCnt == 0) {
            ans.push_back(temp);
            return;
        }
        
        // Include left parentheses
        
        if(leftCnt) {
            temp += "(";
            backtracking(temp, leftCnt - 1, rightCnt);
            temp.pop_back();
        }
        
        // Include right parentheses
        
        if(rightCnt > leftCnt) {
            temp += ")";
            backtracking(temp, leftCnt, rightCnt - 1);
            temp.pop_back();
        }
        
    }
    
    vector<string> generateParenthesis(int n) {
        string temp = "";
        backtracking(temp, n, n);
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 3. Sort Array By Parity

<details>
<summary> View Code </summary>

```cpp
vector<int> sortArrayByParity(vector<int>& A) {
    sort(A.begin(), A.end(), [](int a, int b) {
        return a % 2 < b % 2;
    });
    
    return A;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 4. Min Cost To Connect All Points

<details>
<summary> View Code </summary>

```cpp
class UnionFind {
    private:
        vector<int> id, rank;
        int cnt;
    public:
        UnionFind(int cnt) : cnt(cnt) {
            id = vector<int>(cnt);
            rank = vector<int>(cnt, 0);
            for (int i = 0; i < cnt; ++i) id[i] = i;
        }
        int find(int p) {
            if (id[p] == p) return p;
            return id[p] = find(id[p]);
        }
        int getCount() { 
            return cnt; 
        }
        bool connected(int p, int q) { 
            return find(p) == find(q); 
        }
        void connect(int p, int q) {
            int i = find(p), j = find(q);
            if (i == j) return;
            if (rank[i] < rank[j]) {
                id[i] = j;  
            } else {
                id[j] = i;
                if (rank[i] == rank[j]) rank[j]++;
            }
            --cnt;
        }
};

class Solution {
public:
    int minCostConnectPoints(vector<vector<int>>& points) {
        
        int N = points.size();
        
        vector<array<int, 3>> E;
        
        for(int i = 0; i < N; i++) {
            for(int j = i + 1; j < N; j++) {
                E.push_back({abs(points[i][0] - points[j][0]) + abs(points[i][1] - points[j][1]), i, j});
            }
        }
        
        UnionFind uf(N);
        
        int ans = 0;
        
        // How to convert vector into heap.
        make_heap(E.begin(), E.end(), greater<array<int, 3>>());
        
        while(uf.getCount() > 1) {
            pop_heap(E.begin(), E.end(), greater<array<int, 3>>());
            auto [w, u, v] = E.back();
            
            E.pop_back();
            
            if(uf.connected(u, v)) continue;
            
            uf.connect(u, v);
            ans += w;
        }
        
        return ans;
        
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 5. Power(x, n)

<details>
<summary> View Code </summary>

```cpp
double recursion(double x, long n) {
        
    if(n < 0) {
        return 1 / recursion(x, -n);
    }
    
    if(n == 0) {
        return 1;
    }
    
    if(n == 1) {
        return x;
    }
    
    if(n == 2) {
        return x * x;
    }
    
    return recursion( recursion (x, n / 2), 2) * (n % 2 ? x : 1);
}

double myPow(double x, int n) {
    return recursion(x, (long)n);
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 6. Critical Connections In A Network

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {
        vector<int> ranks(n, INT_MIN);
        
        vector<vector<int>> G(n), ans;
        
        for(auto &e : connections) {
            int u = e[0], v = e[1];
            G[u].push_back(v);
            G[v].push_back(u);
        }
        
        function<int(int, int)> dfs = [&](int u, int rank) {
            if(ranks[u] >= 0) return ranks[u];
            
            ranks[u] = rank;
            int minRank = rank;
            
            for(int v : G[u]) {
                
                if(ranks[v] >= rank - 1) continue; 
                
                int neighbourMinRank = dfs(v, rank + 1);
                minRank = min(minRank, neighbourMinRank);
                
                if (neighbourMinRank > rank) {
                    ans.push_back({u, v});
                }
            }
            
            return minRank;
        };
        
        
        dfs(0, 0);
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 7. Longest Increasing Path In A Matrix

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int M, N;
    vector<vector<int>> cnt;
    
    int dirs[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    
    int dfs(vector<vector<int>> &A, int i, int j) {
        
        if(cnt[i][j] != -1e9) {
            return cnt[i][j];
        }
        
        cnt[i][j] = 1;
        
        for(auto &dir : dirs) {
            int a = i + dir[0];
            int b = j + dir[1];
            
            if(a < 0 || b < 0 || a >= M || b >= N || A[a][b] <= A[i][j]) continue;
            
            cnt[i][j] = max(cnt[i][j] , 1 + dfs(A, a, b));
        }
        
        return cnt[i][j];
    }
    
    int longestIncreasingPath(vector<vector<int>>& matrix) {
        M = matrix.size();
        N = matrix[0].size();
        
        cnt.assign(M, vector<int>(N, -1e9));
        
        int ans = 0;
        
        for(int i = 0; i < M; i++) {
            for(int j = 0; j < N; j++) {
                ans = max(ans, dfs(matrix, i, j));
            }
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 8. Valid Arrangement of Pairs

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> validArrangement(vector<vector<int>>& pairs) {
        unordered_map<int, vector<int>> G;
        unordered_map<int, int> indegrees, outdegrees;
        
        for(auto &e : pairs) {
            int u = e[0], v = e[1];
            G[u].push_back(v);
            indegrees[v]++;
            outdegrees[u]++;
        }
        
        // Select the starting node.
        int start = -1;
        
        for(auto &[u, ad] : G ) {
            if(outdegrees[u] - indegrees[u] == 1) {
                start = u;
                break;
            }
        }
        
        if(start == -1) {
            start = pairs[0][0];
        }
        
        vector<vector<int>> ans;
        
        function<void(int)> euler = [&](int u) {
            
            auto &ad = G[u];
            
            while(ad.size()) {
                int v = ad.back();
                ad.pop_back();
                
                euler(v);
                ans.push_back({u, v});
            }
        };
        
        euler(start);
        reverse(ans.begin(), ans.end());
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 9. Next Greater Element II

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums) {
        int N = nums.size();
        
        // Stores index.
        stack<int> S;
        
        // Stores element
        vector<int> ans(N, -1);
        
        for(int i = 0; i < 2 * N; i++) {
            
            int n = nums[i % N];
            
            while(S.size() && nums[S.top()] < n) {
                ans[S.top()] = n;
                S.pop();
            }
            
            S.push(i % N);
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 10. Container With Most Water

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int maxArea(vector<int>& height) {
        
        int N = height.size();
        int L = 0, R = N - 1;
        
        int ans = 0;
        
        while(L < R) {
            int area = min(height[L], height[R]) * (R - L);
            
            ans = max(ans, area);
            
            if(height[L] < height[R]) {
                L++;
            } else {
                R--;
            }
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 11. Implement Trie (Prefix Tree)

<details>
<summary> View Code </summary>

```cpp
struct TrieNode {
    TrieNode *next[26] = {};
    bool word = false;
};

class Trie {
    
    TrieNode root;
    
    TrieNode *find(string s) {
        
        auto node = &root;
        
        for(char c : s) {
            if(!node->next[c - 'a']) return NULL;
            
            node = node->next[c - 'a'];
        }
        
        return node;
    }
    
public:
    
    void insert(string word) {
        
        auto node = &root;
        
        for(char c : word) {
            if(!node->next[c - 'a']) node->next[c - 'a'] = new TrieNode();
            
            node = node->next[c - 'a'];
        }
        
        node->word = true;
    }
    
    bool search(string word) {
        auto wordFind = find(word);
        return wordFind && (wordFind->word == true);
    }
    
    bool startsWith(string prefix) {
        return find(prefix);
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)



## 12. Sort The Matrix Diagonally

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> diagonalSort(vector<vector<int>>& mat) {
        int M = mat.size();
        int N = mat[0].size();
        
        for (int i = 0; i < M; ++i) {
            vector<int> v;
            for (int x = i, y = 0; x < M && y < N; ++x, ++y) {
                v.push_back(mat[x][y]);
            }
            sort(v.begin(), v.end());
            int index = 0;
            for (int x = i, y = 0; x < M && y < N; ++x, ++y) {
                mat[x][y] = v[index++];
            }
        }
        
         for (int j = 1; j < N; ++j) {
             vector<int> v;
             for(int x = 0, y = j; x < M && y < N; ++x, ++y) {
                 v.push_back(mat[x][y]);
             }
             sort(v.begin(), v.end());
             int index = 0;
             for (int x = 0, y = j; x < M && y < N; ++x, ++y) {
                 mat[x][y] = v[index++];
             }
         }
        
        return mat;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 13. Minimum Window Substring

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    string minWindow(string s, string t) {
        
        unordered_map<char, int> target, cnt;
        int N = s.length();
        
        // Store the frequency of target string
        for(char c : t) {
            target[c]++;
        }
        
        int matched = 0;
        int start = 0, len = INT_MAX;
        int i = 0;
        
        // Traverse the s string, j - right boundary, left boundary - 0
        for(int j = 0; j < N; j++) {
            
            if(++cnt[s[j]] <= target[s[j]]) matched++;
            
            // Target string comes inside this window substring.
            while(matched == t.size()) {
                
                // Update the answer start and its length
                if(len > j - i + 1) {
                    len = j - i + 1;
                    start = i;
                }
                
                // Decrease the length of window.
                if(--cnt[s[i]] < target[s[i]]) matched--;
                i++;
            }
            
        }
        
        if(len == INT_MAX) {
            return "";
        } else {
            return s.substr(start, len);
        }
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 14. Increasing Triplet Subsequence

<details>
<summary> View Code </summary>


```cpp
class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        
        int N = nums.size();
        
        vector<int> dp;
        
        for(int i = 0; i < N; i++) {
            
            auto it = lower_bound(dp.begin(), dp.end(), nums[i]);
            
            if(it != dp.end()) {
                *it = nums[i];
            } else {
                dp.push_back(nums[i]);
            }
        }
        
        return (dp.size() >= 3);
        
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 15. Target Sum

<details>
<summary> Solution - Recursion (TLE) </summary>

```cpp
class Solution {
public:
    
    int recur(vector<int>& nums, int sum, int target, int i) {
        int n = nums.size();
        
        if(n == i) {
            // Check the sum if it is equal to target
            if(sum == target) return 1;
            
            return 0;
        }
        
        int res = 0;
        
        // Include
        res += recur(nums, sum + nums[i], target, i + 1);
        
        // Not Include
        res += recur(nums, sum - nums[i], target, i + 1);
        
        return res;
        
    }
    
    int findTargetSumWays(vector<int>& nums, int target) {
        // (vector, sum, target, index);
        return recur(nums, 0, target, 0);
    }
};
```
</details>

<details>
<summary> Solution - DP </summary>

```cpp
class Solution {
public:
    int recursion(vector<int>& nums, int sum, int target, int i, vector<vector<int>> &dp) {
        
        if(i == nums.size()) {
            return sum == target;
        }
        
        if(dp[i][sum + 1000] != -1) return dp[i][sum + 1000];
        
        
        int include = recursion(nums, sum + nums[i], target, i + 1, dp);
        int notInclude = recursion(nums, sum - nums[i], target, i + 1, dp);
        
        dp[i][sum + 1000] = include + notInclude;
        
        return dp[i][sum + 1000];
    }   
    
    int findTargetSumWays(vector<int>& nums, int target) {
        vector<vector<int>> dp(nums.size() + 1, vector<int>(3000, -1));
        return recursion(nums, 0, target, 0, dp);
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 16. Check If There Is A Valid Partition For The Array

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool validPartition(vector<int>& nums) {
        int N = nums.size();
        bool dp[N + 1];
        
        for(int i = 0; i <= N; i++) dp[i] = false;
        
        dp[0] = true;
        
        for(int i = 0; i < N; i++) {
            // for two elements
            if(i >= 1) {
                if(dp[i - 1] && nums[i] == nums[i - 1]) {
                    dp[i + 1] = true;
                }
            }
            
            // for three elements
            if(i >= 2) {
                if(dp[i - 2] && nums[i] == nums[i - 1] && nums[i - 1] == nums[i - 2]) {
                    dp[i + 1] = true;
                }
            }
            
            // for three consecutive elements
            if(i >= 2) {
                if(dp[i - 2] && nums[i] == nums[i - 1] + 1 && nums[i - 1] == nums[i - 2] + 1) {
                    dp[i + 1] = true;
                }
            }
        }
        
        return dp[N];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 17. Longest Consecutive Sequence

<details>
<summary> View Code </summary>

```cpp
// Union Find that also return the vector of size of components.
class UnionFind {
    vector<int> id, size;
public:
    UnionFind(int n) : id(n), size(n, 1) {
        for (int i = 0; i < n; ++i) id[i] = i;
    }
    void connect(int a, int b) {
        int x = find(a), y = find(b);
        if (x == y) return;
        id[x] = y;
        size[y] += size[x];
    }
    int find(int a) {
        return id[a] == a ? a : (id[a] = find(id[a]));
    }
    vector<int> &getSizes() {
        return size;
    }
};

class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        
        int N = nums.size();
        
        if(N == 0) {
            return 0;
        }
        
        UnionFind uf(N);
        
        unordered_map<int, int> M;
        
        // We have to store indexes in UnionFind instead of integer values.
        
        for(int i = 0; i < N; i++) {
            int n = nums[i];
            
            if(M.count(n)) continue;
            
            M[n] = i;
            
            if(M.count(n - 1)) uf.connect(M[n], M[n - 1]);
            if(M.count(n + 1)) uf.connect(M[n], M[n + 1]);
        }
        
        // ans -> maximum component size
        vector<int> ans = uf.getSizes();
        return *max_element(ans.begin(), ans.end());
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 18. Valid Sudoku

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        int row[9][9] = {}, col[9][9] = {}, box[9][9] = {};
        
        for(int i = 0; i < 9; i++) {
            for(int j = 0; j < 9; j++) {
                int n = board[i][j] - '1';
                
                if(board[i][j] == '.') continue;
                
                if(row[i][n] || col[j][n] || box[(i / 3) * 3 + (j / 3)][n]) return false;
                
                
                row[i][n] = col[j][n] = box[i / 3 * 3 + j / 3][n] = 1;
            }
        }
        
        return true;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 19. My Calendar I

<details>
<summary> View Code </summary>


```cpp
class MyCalendar {
public:
    MyCalendar() {
        
    }

    map<int, int> M;
    
    bool book(int start, int end) {
        
        if(M.empty()) {
            M[start] = end;
            return true;
        }
        
        // Conditions 
        
        auto it = M.upper_bound(start);
        
        // Check the later intersection
        if(it != M.end() && it->first < end) return false;
        
        // Check the starting intersection
        if(it != M.begin() && prev(it)->second > start) return false;
        
        
        // After checking conditions
        M[start] = end;
        return true;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 20. Sliding Window Maximum

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<int> maxSlidingWindow(vector<int>& nums, int k) {
        int N = nums.size();
        deque<int> d; // Deque will store the index
        
        vector<int> ans;
        
        for(int i = 0; i < N; i++) {
            
            int n = nums[i];
            
            // When the element goes out of window, remove from the deque.
            if(d.size() && d.front() == i - k) d.pop_front();
            
            // We have to store monotonically decreasing sequence.
            while(d.size() && nums[d.back()]  <= n) {
                d.pop_back();
            }
            
            d.push_back(i);
            
            if(i >= k - 1) {
                // Push maximum element in answer.
                ans.push_back(nums[d.front()]);
            }
            
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 21. Best Time To Buy and Sell Stock

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int N = prices.size();
        
        int minStock = prices[0];
        int profit = 0;
        
        for(int i = 0; i < N; i++) {
            minStock = min(minStock, prices[i]);
            
            profit = max(profit, prices[i] - minStock);
        }
        
        return profit;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 22. Maximum Subarray

<details>
<summary> View Code </summary>

```cpp
int maxSubArray(vector<int>& nums) {
    int global = nums[0];
    int local = 0;
    
    int N = nums.size();
    
    for(int i = 0; i < N; i++) {
        local = max(local + nums[i], nums[i]);
        global = max(global, local);
    }
    
    return global;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 23. Cracking The Safe

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    string crackSafe(int n, int k) {
        
        if(n == 1 && k == 1) return "0";
        
        // Store the edges of graph.
        unordered_set<string> M; 
        
        string start = string(n - 1, '0');
        string ans = "";
        
        function<void(string)> euler = [&](string u) {      
            for(char c = '0'; c < k + '0'; c++) {
                // How to use the last sequence optimally
                string v = u + c;

                // We don't have to visit the same edge again
                if(M.count(v)) continue;
                M.insert(v);
                
                euler(v.substr(1));

                ans.push_back(c);
            }
        };
        
        euler(start);
        
        return ans + start;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 24. Find If Path Exists In Graph

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {
        
        // Creation of Graph
        unordered_map<int, vector<int>> G;
        
        for(auto &e : edges) {
            int u = e[0], v = e[1];
            G[u].push_back(v);
            G[v].push_back(u);
        }
        
        // BFS
        
        queue<int> q;
        vector<int> seen(n, 0); // 0 ->unseen
        
        q.push(source);
        seen[source] = 1;
        
        while(q.size()) {
            int v = q.front();
            q.pop();
            // Traverse every edge of v in breadth first search
            
            for(int u : G[v]) {
                if(seen[u]) continue;
                seen[u] = 1;
                q.push(u);
            }
        }
        
        if(seen[destination] == 1) {
            return true;
        } else {
            return false;
        }
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 25. Next Greater Node In Linked List

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    ListNode* reverseList(ListNode* head) {
        ListNode *prev = new ListNode();
        
        while(head) {
            auto node = head;
            head = head->next;
            node->next = prev->next;
            prev->next = node;
        }

        return prev->next;
    }
    
    vector<int> nextLargerNodes(ListNode* head) {
        head = reverseList(head);
        
        stack<int> S;
        vector<int> ans;
        
        
        while(head) {
            
            int n = head->val;
            
            while(S.size() && S.top() <= n) {
                S.pop();
            }
            
            if(S.size() == 0) {
                ans.push_back(0);
            } else {
                ans.push_back(S.top());
            }
            
            S.push(n);
            
            head = head->next;
        }
        
        reverse(ans.begin(), ans.end());
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 26. Repeated Substring Pattern

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool repeatedSubstringPattern(string s) {
        int N = s.length();
        
        for(int len = 1; len <= N / 2; len++) {
            if(N % len) continue;
            
            int i = len;
            for(; i < N; i++) {
                if( s[i] != s[i % len]) break;
            }
            
            if(i == N) return true;
        }
        
        return false;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 27. Search Suggestion System

<details>
<summary> View Code </summary>

```cpp
struct TrieNode {
    TrieNode *next[26] = {};
    int index = -1;
};

void add(TrieNode *node, string &s, int i) {
    
    for(char c: s) {
        if(!node->next[c - 'a']) node->next[c - 'a'] = new TrieNode();
        node = node->next[c - 'a'];
    }
    node->index = i;
}

void collect(TrieNode *node, vector<string> &ans, vector<string> &products) {
    if(ans.size() == 3) return;
    
    if(!node) return;
    
    if(node->index > -1) ans.push_back(products[node->index]);
    
    for(int i = 0; i < 26; i++) {
        if(node->next[i]) collect(node->next[i], ans, products);
    }
}

class Solution {
public:
    vector<vector<string>> suggestedProducts(vector<string>& products, string searchWord) {
        TrieNode root, *node = &root;
        
        for(int i = 0; i < products.size(); i++) {
            add(&root, products[i], i);
        }
        
        vector<vector<string>> ans(searchWord.size());
        
        for(int i = 0; i < searchWord.length(); i++) {
            node = node->next[searchWord[i] - 'a'];
            
            if(!node) break;
            
            collect(node, ans[i], products);
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 28. Merge K Sorted Lists

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    ListNode* mergeKLists(vector<ListNode*>& lists) {
        ListNode dummy, *tail = &dummy;
        auto cmp = [](auto a, auto b) { return a->val > b->val; };
        priority_queue<ListNode*, vector<ListNode*>, decltype(cmp)> q(cmp);
        for (auto list : lists) {
            if (list) q.push(list); // avoid pushing NULL list.
        }
        while (q.size()) {
            auto node = q.top();
            q.pop();
            if (node->next) q.push(node->next);
            tail->next = node;
            tail = node;
        }
        return dummy.next;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 29. Daily Temperatures

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& A) {
        stack<int> s;
        vector<int> ans(A.size());
        for (int i = A.size() - 1; i >= 0; --i) {
            while (s.size() && A[s.top()] <= A[i]) s.pop();
            ans[i] = s.size() ? s.top() - i : 0;
            s.push(i);
        }
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 30. Merge Intervals

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        
        sort(intervals.begin(), intervals.end());
        vector<vector<int>> ans;
        
        for(auto &a : intervals) {
            if(!ans.size() || a[0] > ans.back()[1]) {
                ans.push_back(a);
            } else if(ans.back()[1] < a[1]) {
                ans.back()[1] = a[1];
            }
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 31. Word Ladder

<details>
<summary> View Code </summary>

```cpp
int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
    unordered_set<string> s(begin(wordList), end(wordList));
    if (s.count(endWord) == 0) return 0;
    queue<string> q{{beginWord}};
    s.erase(beginWord);
    int step = 1;
    while (q.size()) {
        int cnt = q.size();
        while (cnt--) {
            auto u = q.front();
            q.pop();
            if (u == endWord) return step;
            for (char &c : u) { // add unvisited neighbors of `u`
                char tmp = c;
                for (char ch = 'a'; ch <= 'z'; ++ch) {
                    if (tmp == ch) continue;
                    c = ch;
                    if (s.count(u) == 0) continue;
                    s.erase(u);
                    q.push(u);
                }
                c = tmp;
            }
        }
        ++step;
    }
    return 0;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 32. 3Sum

<details>
<summary> View Code </summary>

```cpp
vector<vector<int>> threeSum(vector<int>& A) {
    vector<vector<int>> ans;
    sort(A.begin(), A.end());
    
    int N = A.size();
    int L = 0, R = N - 1;
    
    for(int i = 0; i < N - 2; i++) {
        
        if(i > 0 && A[i] == A[i - 1]) continue;
        
        int L = i + 1, R = N - 1;
        
        while(L < R) {
            int sum = A[i] + A[L] + A[R];
            
            if(sum == 0) {
                ans.push_back({A[i], A[L], A[R]});
            }
            
            if(sum <= 0) {
                L++;

                while(L < R && A[L] == A[L - 1]) L++;
            }
            
            if(sum >= 0) {
                R--;

                while(L < R && A[R] == A[R + 1]) R--;
            }
        }
    }
    
    return ans;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 33. Flatten Binary Tree To Linked List

<details>
<summary> View Code </summary>

```cpp
void flatten(TreeNode* root) {
    if(!root) return;
    TreeNode *tail = nullptr;
    
    stack<TreeNode*> S;
    
    S.push({root});
    
    while(S.size()) {
        auto node = S.top();
        S.pop();
        
        if(tail) tail->right = node;
        tail = node;
        
        if(node->right) S.push(node->right);
        if(node->left) S.push(node->left);
        
        node->left = node->right = nullptr;
    }
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 34. Sum of Subarray Minimums

<details>
<summary> View Code </summary>

```cpp
int sumSubarrayMins(vector<int>& A) {
    stack<int> q;
    q.push(-1);
    long N = A.size(), ans = 0, sum = 0, mod = 1e9+7;
    for (int i = 0; i < N; ++i) {
        sum = (sum + A[i]) % mod;
        while (q.top() != -1 && A[q.top()] >= A[i]) {
            int j = q.top();
            q.pop();
            int c = j - q.top();
            sum = (sum + c * (A[i] - A[j]) % mod) % mod;
        }
        q.push(i);
        ans = (ans + sum) % mod;
    }
    return ans;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 35. Median of Two Sorted Arrays

<details>
<summary> View Code </summary>

```cpp
double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {
    if (nums1.size() > nums2.size()) swap(nums1, nums2);
    int M = nums1.size(), N = nums2.size(), L = 0, R = M, K = (M + N + 1) / 2;
    while (true) {
        int i = (L + R) / 2, j = K - i;
        if (i < M && nums2[j - 1] > nums1[i]) L = i + 1;
        else if (i > L && nums1[i - 1] > nums2[j]) R = i - 1;
        else {
            int maxLeft = max(i ? nums1[i - 1] : INT_MIN, j ? nums2[j - 1] : INT_MIN);
            if ((M + N) % 2) return maxLeft;
            int minRight = min(i == M ? INT_MAX : nums1[i], j == N ? INT_MAX : nums2[j]);
            return (maxLeft + minRight) / 2.0;
        }
    }
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 36. LRU Cache

<details>
<summary> View Code </summary>

```cpp
class LRUCache {
    int capacity;
    list<pair<int, int>> data;
    unordered_map<int, list<pair<int, int>>::iterator> m;
    void moveToFront(int key) {
        auto node = m[key];
        data.splice(data.begin(), data, node);
        m[key] = data.begin();
    }
public:
    LRUCache(int capacity) : capacity(capacity) {}
    int get(int key) {
        // get node given key, put the node at the beginning of the list, return the value in the node
        if (m.count(key)) {
            moveToFront(key);
            return m[key]->second;
        }
        return -1;
    }
    void put(int key, int value) {
        // if key exists in the map, get node given key, put the node at the beginning of the list and update the value in the node
        // otherwise, put a new node at the beginning of the list with the <key, value> and update the map. If capacity exceeded, remove the last node from the list and map.
        if (m.count(key)) {
            moveToFront(key);
            m[key]->second = value;
        } else {
            data.emplace_front(key, value);
            m[key] = data.begin();
            if (data.size() > capacity) {
                m.erase(data.rbegin()->first);
                data.pop_back();
            }
        }
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 37. Gas Station

<details>
<summary> View Code </summary>

```cpp
int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
    int N = gas.size(), len = 0, start = 0;
    for (int i = 0, sum = 0; i < 2 * N && len < N; ++i) {
        sum += gas[i % N] - cost[i % N];
        if (sum < 0) {
            len = sum = 0;
            start = (i + 1) % N;
        } else ++len;
    }
    return len == N ? start : -1;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 38. Max Points On A Line

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int maxPoints(vector<vector<int>>& points) {
        
        int res = 0;
        for(int i = 0; i<points.size(); i++){
            
            unordered_map<long double,int> noOfPointsInLine;
            
            for(int j = i + 1; j < points.size(); j++){
                
                int x1 = points[i][0], y1 = points[i][1], x2 = points[j][0], y2 = points[j][1];
                
                if(y2 == y1) {     
                    noOfPointsInLine[INT_MIN]++;
                } else if(x1 == x2){ 
                    noOfPointsInLine[INT_MAX]++;
                } else {               
                    long double slope = (long double)(y2 - y1) /(long double)(x2 - x1);
                    noOfPointsInLine[slope]++;
                }
                
            }
            
            for(auto i : noOfPointsInLine){
                res = max(i.second, res);
            }
        }
        return res + 1;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 39. Largest Rectangle In Histogram

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int largestRectangleArea(vector<int>& A) {
        int N = A.size();
        
        int ans = 0;
        
        stack<int> S;
        vector<int> next(N, N), prev(N, -1);
        
        for(int i = 0; i < N; i++) {
            while(S.size() && A[i] < A[S.top()]) {
                next[S.top()] = i;
                S.pop();
            }
            S.push(i);
        }
        
        for(int i = N - 1; i >= 0; i--) {
            while(S.size() && A[i] < A[S.top()]) {
                prev[S.top()] = i;
                S.pop();
            }
            S.push(i);
        }
        
        for(int i = 0; i < N; i++) {
            ans = max(ans, A[i] * (next[i] - prev[i] - 1));
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 40. Regular Expression Matching

<details>
<summary> View Code </summary>

```cpp
class Solution {
private:
    inline bool matchChar(string &s, int i, string &p, int j) {
        return p[j] == '.' ? i < s.size() : s[i] == p[j];
    }
    bool isMatch(string s, int i, string p, int j) {
        if (j == p.size()) return i == s.size();
        if (j + 1 < p.size() && p[j + 1] == '*') {
            bool ans = false;
            while (!(ans = isMatch(s, i, p, j + 2))
            && matchChar(s, i, p, j)) ++i;
            return ans;
        } else {
            return matchChar(s, i, p, j) && isMatch(s, i + 1, p, j + 1);
        }
    }
public:
    bool isMatch(string s, string p) {
        return isMatch(s, 0, p, 0);
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 41. Minimum Deletions To Make Character Frequencies Unique

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int minDeletions(string s) {
        int cnt[26] = {0};
        set<int> S;
        int ans = 0;
        for (char c : s) {
          cnt[c - 'a']++;  
        } 
        
        for(int i = 0; i < 26; i++) {
            while(cnt[i]-- && !S.insert(cnt[i]).second) {
                ans++;
            }
        }
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 42. Jump Game II

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int jump(vector<int>& nums) {
        int N = nums.size();
        vector<int> dp(N, 1e9);
        
        dp[0] = 0;
        
        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= nums[i] && i + j < N; j++) {
                dp[i + j] = min(dp[i + j], 1 + dp[i]);
            }
        }
        
        return dp[N - 1];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 43. Count Good Nodes In Binary Tree

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int ans = 0;
    int dfs(TreeNode* root, int maxVal) {
        if(root->val >= maxVal) {
            ans++;
        }
        maxVal = max(maxVal, root->val);
        
        if(root->left) {
            dfs(root->left, maxVal);
        }
        
        if(root->right) {
            dfs(root->right, maxVal);
        }
        
        return ans;
    }
    int goodNodes(TreeNode* root) {
        return dfs(root, INT_MIN);
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 44. Unique Paths

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int uniquePaths(int m, int n) {
        vector<int> dp(n + 1, 0);
        dp[n - 1] = 1;
        
        for(int i = m - 1; i >= 0; i--) {
            for(int j = n - 1; j >= 0; j--){
                dp[j] += dp[j + 1];
            }
        }
        
        return dp[0];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 45. Coin Change

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int coinChange(vector<int>& coins, int amount) {
        int dp[amount + 1];
        dp[0] = 0;
        
        sort(coins.begin(), coins.end());
        
        for(int i = 1; i <= amount; i++) {
            
            dp[i] = INT_MAX;
            for(auto &coin : coins) {
                if(i - coin < 0) break;
                
                if(dp[i - coin] != INT_MAX) {
                    dp[i] = min(dp[i], 1 + dp[i - coin]);
                }
            }
        }
        
        if(dp[amount] != INT_MAX) {
            return dp[amount];
        } else {
            return -1;
        }
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 46. Is Graph Bipartite ?

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool isBipartite(vector<vector<int>>& G) {
        int N = G.size();
        vector<int> id(N); // 0 unseen, 1 and -1 are different colors
        function<bool(int, int)> dfs = [&](int u, int color) {
            if (id[u]) return id[u] == color;
            id[u] = color;
            for (int v : G[u]) {
                if (!dfs(v, -color)) return false;
            }
            return true;
        };
        for (int i = 0; i < N; ++i) {
            if (!id[i] && !dfs(i, 1)) return false;
        }
        return true;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 47. Frequency of Most Frequent Elements

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int maxFrequency(vector<int>& A, int k) {
        int N = A.size();
        
        sort(A.begin(), A.end());
        
        long ans = 1, sum = 0, i = 0;
        
        for(int j = 0; j < N; j++) {
            sum += A[j];
            
            // Increase the left boundary of window :
            // (Length of window * currentElement) - Sum of all elements > k 
            while( (j - i + 1) * A[j] - sum > k) {
                sum -= A[i++];
            }
            
            ans = max(ans, j - i + 1);
            
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 48. Group Anagrams

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        
        unordered_map<string, vector<string>> M;
        
        for(string &s : strs) {
            
            string t = s;
            sort(t.begin(), t.end());
            
            M[t].push_back(s);
        }
        
        vector<vector<string>> ans;
        
        for(auto &[s, vs] : M) {
            ans.push_back(vs);    
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 49. Satisfiability of Equality Equations

<details>
<summary> View Code </summary>

```cpp
class UnionFind {
    private:
        vector<int> id, rank;
        int cnt;
    public:
        UnionFind(int cnt) : cnt(cnt) {
            id = vector<int>(cnt);
            rank = vector<int>(cnt, 0);
            for (int i = 0; i < cnt; ++i) id[i] = i;
        }
        int find(int p) {
            if (id[p] == p) return p;
            return id[p] = find(id[p]);
        }
        int getCount() { 
            return cnt; 
        }
        bool connected(int p, int q) { 
            return find(p) == find(q); 
        }
        void connect(int p, int q) {
            int i = find(p), j = find(q);
            if (i == j) return;
            if (rank[i] < rank[j]) {
                id[i] = j;  
            } else {
                id[j] = i;
                if (rank[i] == rank[j]) rank[j]++;
            }
            --cnt;
        }
};

class Solution {
public:
    bool equationsPossible(vector<string>& equations) {
        int N = equations.size();
        
        UnionFind uf(26);
        
        for(auto &e : equations) {
            if(e[1] == '=') {
                int num1 = e[0] - 'a';
                int num2 = e[3] - 'a';
                uf.connect(num1, num2);
            }
        }
        
        for(auto &e : equations) {
            if(e[1] == '!') {
                int num1 = e[0] - 'a';
                int num2 = e[3] - 'a';
                if(uf.connected(num1, num2)) {
                    return false;
                }
            }
        }
        
        return true;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 50. Range Sum BST

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int sum = 0;
    
    void preorder(TreeNode* root, int L, int R) {
        if(!root) {
            return;
        }
        
        if(root->val >= L && root->val <= R) {
            sum += root->val;
        }
        
        preorder(root->left, L, R);
        preorder(root->right, L, R);
    }
    
    int rangeSumBST(TreeNode* root, int low, int high) {
        preorder(root, low, high);
        return sum;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)


## 51. Number of Islands

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    int M, N;
    
    int dirs[4][2] = { {0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    
    void dfs(vector<vector<char>> &grid, int i, int j) {
        
        // This cell of grid has been visited.
        grid[i][j] = '2';
        
        // Go to the four sides of grid.
        for(auto &dir : dirs) {
            int a = i + dir[0];
            int b = j + dir[1];
            
            if(a < 0 || b < 0 || a >= M || b >= N || grid[a][b] != '1') continue;
            
            dfs(grid, a, b);
        }
    }
    
    int numIslands(vector<vector<char>>& grid) {
        M = grid.size();
        N = grid[0].size();
        
        int islandCnt = 0;
        
        for(int i = 0; i < M; i++) {
            for(int j = 0; j < N; j++) {
                if(grid[i][j] == '1') {
                    dfs(grid, i, j);
                    islandCnt++;
                }
            }
        }
        
        return islandCnt;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 52. Wildcard Matching

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    int M, N;
    vector<vector<int>> dp;
    
    bool wildcardMatching(string &s, string &p, int i, int j) {
        
        if(dp[i][j] != -1) return dp[i][j]; 
        int &ans = dp[i][j];
        
        for(; j < N; j++) {
            
            if(p[j] != '*' && i >= M) return ans = false;
            if(p[j] == '?') {
                i++;
            } else if(p[j] == '*') {
                while(j + 1 < N && p[j + 1] == '*') j++;
                for(int k = 0; i + k <= M; i++) {
                    if(wildcardMatching(s, p, i + k, j + 1)) {
                        return ans = true;
                    }
                }
            } else if(s[i++] != p[j]) {
                return ans = false;
            }
        }
        
        return ans = i >= M;
        
    }
    
    bool isMatch(string s, string p) {
        M = s.size();
        N = p.size();
        
        dp.assign(M + 1, vector<int>(N + 1, -1));
        return wildcardMatching(s, p, 0, 0);
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 53. Min Stack

<details>
<summary> View Code </summary>

```cpp
class MinStack {
public:
    
    stack<int> S, M;
    
    void push(int val) {
        S.push(val);
        if(M.empty() || M.top() >= val) {
            M.push(val);
        }
    }
    
    void pop() {
        int x = S.top();
        S.pop();
        
        // If popped element is minimum
        if(M.top() == x) {
            M.pop();
        }
    }
    
    int top() {
        return S.top();
    }
    
    int getMin() {
        return M.top();
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 54. Permutations

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    vector<vector<int>> ans;
    
    void permute(vector<int> &nums, int start) {
        // Base case
        if(start == nums.size()) {
            ans.push_back(nums);
            return;
        }
        
        for(int i = start; i < nums.size(); i++) {
            swap(nums[start], nums[i]);
            permute(nums, start + 1);
            swap(nums[start], nums[i]);
        }
        
    }
    
    vector<vector<int>> permute(vector<int>& nums) {
        permute(nums, 0);
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 55. Combinations

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    vector<vector<int>> ans;
    
    void combine(vector<int> &temp, int n, int k, int start) {
        // Base case
        if(temp.size() == k) {
            ans.push_back(temp);
            return;
        }
        
        for(int i = start, end = n - k + temp.size(); i <= end; i++) {
            temp.push_back(i + 1);
            combine(temp, n, k, i + 1);
            temp.pop_back();
        }
    }
    
    vector<vector<int>> combine(int n, int k) {
        vector<int> temp;
        combine(temp, n, k, 0);
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 56. Diameter of Binary Tree

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int diameter = 0;

    int dfs(TreeNode* root) {
        if(!root) {
            return 0;
        }
        
        int left = dfs(root->left);
        int right = dfs(root->right);
        
        diameter = max(diameter, left + right);
        
        return (1 + max(left, right));
    }
    
    int diameterOfBinaryTree(TreeNode* root) {
        dfs(root);
        return diameter;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 57. Peak Index In Mountain Array

<details>
<summary> View Code </summary>

```cpp
int peakIndexInMountainArray(vector<int>& arr) {
    int N = arr.size();
    
    int L = 1, R = N - 2, M;
    
    while(L <= R) {
        M = (L + R) / 2;
        
        if(arr[M] > arr[M - 1]) {
            L = M + 1;
        } else {
            R = M - 1;
        }
    }
    
    return R;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 58. Maximum Depth of Binary Tree

<details>
<summary> View Code </summary>

```cpp
int maxDepth(TreeNode* root) {
    if(!root) {
        return 0;
    }
    
    return (1 + max(maxDepth(root->left), maxDepth(root->right)));
}
```

</details>

<br>[⬆ Back to top](#table-of-contents)


## 59. Find Minimum In Rotated Sorted Array

<details>
<summary> View Code </summary>

```cpp
int findMin(vector<int>& nums) {
    int N = nums.size();
    
    int L = 0, R = N - 1, M;
    
    while(L < R) {
        M = (L + R) / 2;
        
        if(nums[M] < nums[R]) {
            R = M;
        } else {
            L = M + 1;
        }
    }
    
    return nums[R];
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 60. Binary Tree Zigzag Level Order Traversal

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    vector<vector<int>> ans;
    
    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
        if(!root) {
            return {};
        }
        
        bool l2r = true;
        
        queue<TreeNode*> q;
        q.push({root});
        
        while(q.size()) {
            int cnt = q.size();
            
            vector<int> temp;
            
            while(cnt--) {
                auto node = q.front();
                q.pop();
                
                temp.push_back(node->val);
                
                if(node->left) {
                    q.push(node->left);
                }
                
                if(node->right) {
                    q.push(node->right);
                }
            }
            
            if(!l2r) {
                reverse(temp.begin(), temp.end());
            }
            
            l2r = !l2r;
            ans.push_back(temp);
        }
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 61. Longest Substring Without Repeating Characters

<details>
<summary> View Code </summary>

```cpp
int lengthOfLongestSubstring(string s) {
    int N = s.length();
    int length = 0, i = 0;
    unordered_map<int, int> M;
    
    for(int j = 0; j < N; j++) {
        
        M[s[j]]++;
        
        // Increase the window size from left side if there are multiple characters
        while(M[s[j]] > 1) {
            M[s[i++]]--;
        }
        
        length = max(length, j - i + 1);
    }
    
    return length;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 62. Combination Sum

<details>
<summary> View Code </summary>

```cpp
vector<vector<int>> combinationSum(vector<int>& A, int target) {
    vector<vector<int>> ans;
    vector<int> tmp;
    sort(begin(A), end(A));
    function<void(int, int)> dfs = [&](int start, int goal) {
        if (goal == 0) {
            ans.push_back(tmp);
        }
        for (int i = start; i < A.size() && gaol - A[i] >= 0; ++i) {
            tmp.push_back(A[i]);
            dfs(i, goal - A[i]);
            tmp.pop_back();
        }
    };
    dfs(0, target);
    return ans;
}
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 63. N-Queens

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<string>> ret;
    
    bool is_valid(vector<string> &board, int row, int col) {
        
        for(int i = row; i >= 0; --i) {
            if(board[i][col] == 'Q') return false;
        }
            
        for(int i = row, j = col; i >= 0 && j >= 0; --i, --j) {
            if(board[i][j] == 'Q') return false;
        }
        
        for(int i = row, j = col; i >= 0 && j < board.size(); --i, ++j) {
            if(board[i][j] == 'Q') return false;
        }
            
        return true;
    }
    
    void dfs(vector<string> &board, int row){
        if(row == board.size()){
            ret.push_back(board);
            return;
        }
        
        for(int i=0; i < board.size(); ++i) {
            if(is_valid(board, row, i)){
                board[row][i] = 'Q';
                dfs(board, row + 1);
                board[row][i] = '.';
            }
        }
    }
    
    vector<vector<string>> solveNQueens(int n) {
        vector<string>board(n, string(n, '.'));
        dfs(board, 0);
        return ret;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 64. Subsets

<details>
<summary> View Code </summary>

```cpp
vector<vector<int>> subsets(vector<int>& A) {
    vector<vector<int>> ans;
    vector<int> tmp;
    function<void(int)> dfs = [&](int i) {
        if (i == A.size()) {
            ans.push_back(tmp);
            return;
        }
        tmp.push_back(A[i]);
        dfs(i + 1); // Pick A[i]
        tmp.pop_back();
        dfs(i + 1); // Skip A[i]
    };
    dfs(0);
    return ans;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 65. Pascal's Triangle

<details>
<summary> View Code </summary>

```cpp
vector<vector<int>> generate(int numRows) {
    vector<vector<int>> ans(numRows);
    for (int i = 0; i < numRows; ++i) {
        ans[i] = vector<int>(i + 1, 1);
        for (int j = 1; j < i; ++j) ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j];
    }
    return ans;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 66. House Robber II

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int rob(vector<int>& nums) {
        int N = nums.size();
        
        if(N == 1) return nums[0];
        
        if(N == 2) return max(nums[0], nums[1]);
        
        return max(robber(nums, 0, N - 2), robber(nums, 1, N - 1));
    }
    
    int robber(vector<int> &nums, int l, int r) {
        int pre = 0, cur = 0;
        
        for(int i = l; i <= r; i++) {
            int temp = max(pre + nums[i], cur);
            pre = cur;
            cur = temp;
        }
        
        return cur;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 67. Partition Equal Subset Sum

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> dp;
    bool recurse(vector<int>& nums, int i, int target, vector<vector<int>> &dp) {
        if(i >= nums.size()) {
            return false;
        }
        if(target <= 0) {
            return target == 0;
        }
        if(dp[i][target] != -1) {
            return dp[i][target];
        } 
        
        return dp[i][target] = (recurse(nums, i + 1, target - nums[i], dp) || recurse(nums, i + 1, target, dp));
    }
    
    bool canPartition(vector<int>& nums) {
        
        int sum = accumulate(nums.begin(), nums.end(), 0);
        if(sum % 2) return false;
        sum /= 2;
        dp.assign(nums.size() + 1, vector<int>(sum + 1, -1));
        return recurse(nums, 0, sum, dp);
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 68. Number of Submatrices That Sum To Target

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {
        int M = matrix.size(), N = matrix[0].size(), ans = 0;
        vector<vector<int>> sum(M + 1, vector<int>(N + 1, 0));
        for (int i = 1; i <= M; ++i) {
            for (int j = 1; j <= N; ++j) {
                sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + matrix[i - 1][j - 1];
            }
        }
        for (int i = 0; i < N; ++i) {
           for (int j = i + 1; j <= N; ++j) {
               unordered_map<int, int> m {{ 0, 1 }};
               for (int k = 1; k <= M; ++k) {
                   int val = sum[k][j] - sum[k][i];
                   ans += m[val - target];
                   m[val]++;
               }
           }
        }
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)


## 69. Shortest Path in Binary Matrix

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int dirs[8][2] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
    int shortestPathBinaryMatrix(vector<vector<int>>& G) {
        if (G[0][0] == 1) return -1;
        int N = G.size();
        vector<vector<int>> dist(N, vector<int>(N, INT_MAX));
        queue<pair<int, int>> q;
        q.emplace(0, 0);
        dist[0][0] = 1;
        while (q.size()) {
            auto [x, y] = q.front();
            q.pop();
            for(int i = 0; i < 8; i++) {
                int a = x + dirs[i][0];
                int b = y + dirs[i][1];
                if (a < 0 || a >= N || b < 0 || b >= N || G[a][b] == 1 || dist[a][b] != INT_MAX) continue;
                dist[a][b] = dist[x][y] + 1;
                q.emplace(a, b);
            }
        }
        return dist[N - 1][N - 1] == INT_MAX ? -1 : dist[N - 1][N - 1];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 70.Validate Binary Search Tree

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    bool isValidBST(TreeNode* root, TreeNode* left = NULL, TreeNode* right = NULL) {
        if(!root) {
            return true;
        }
        
        if(left && root->val <= left->val || right && root->val >= right->val) {
            return false;
        }
        
        return (isValidBST(root->left, left, root) && isValidBST(root->right, root, right));
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 71. Reverse Nodes in k-Group

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode h, *tail = &h;
        while (head) {
            auto prev = tail;
            int i = 0;
            for (auto p = head; i < k && p; ++i, p = p->next);
            if (i < k) {
                tail->next = head;
                break;
            }
            for (int i = 0; i < k && head; ++i) {
                auto node = head;
                head = head->next;
                node->next = prev->next;
                prev->next = node;
            }
            while (tail->next) tail = tail->next;
        }
        return h.next;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 72. Trapping Rain Water

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int trap(vector<int>& A) {
        int N = A.size(), ans = 0;
        vector<int> left(N, 0), right(N, 0);
        for (int i = 1; i < N; ++i) left[i] = max(left[i - 1], A[i - 1]);
        for (int i = N - 2; i >= 0; --i) right[i] = max(right[i + 1], A[i + 1]);
        for (int i = 1; i < N - 1; ++i) ans += max(0, min(left[i], right[i]) - A[i]);
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 73. Find Missing Positive

<details>
<summary> View Code </summary>

```cpp
int firstMissingPositive(vector<int>& A) {
    int i, N = A.size();
    for (i = 0; i < N; ) {
        if (A[i] == i + 1 || A[i] < 1 || A[i] >= N + 1 || A[i] == A[A[i] - 1]) ++i;
        else swap(A[i], A[A[i] - 1]);
    }
    for (i = 0; i < N && A[i] == i + 1; ++i);
    return i + 1;
}

int firstMissingPositive(vector<int>& nums) {
    int N = nums.size();
    // Ignore negatives and zero.
    for(int i = 0; i < N; i++) if(nums[i] <= 0) nums[i] = N + 1;
    
    // Replacing numbers with their negatives
    for(int i = 0; i < N; i++) {
        if(abs(nums[i]) <= N && nums[abs(nums[i]) - 1] > 0) {
            nums[abs(nums[i]) - 1] *= -1;
        }
    }
    
    for(int i = 0; i < N; i++) {
        if(nums[i] > 0) {
            return i + 1;
        }
    }
    
    return N + 1;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 74. Edit Distance

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int minDistance(string word1, string word2) {
        int M = word1.size();
        int N = word2.size();
        if(!M) return N;
        if(!N) return M;
        
        vector<vector<int>> dp(M + 1, vector<int>(N + 1, INT_MAX));
        
        dp[0][0] = 0;
        
        for(int i = 0; i < M; i++) {
            dp[i + 1][0] = i + 1;
        }
        
        for(int j = 0; j < N; j++) {
            dp[0][j + 1] = j + 1;
        }
        
        for(int i = 0; i < M; i++) {
            for(int j = 0; j < N; j++) {
                if(word1[i] == word2[j]) {
                    dp[i + 1][j + 1] = dp[i][j];
                } else {
                    dp[i + 1][j + 1] = 1 + min({dp[i][j], dp[i + 1][j], dp[i][j + 1]});
                }
            }
        }
        
        return dp[M][N];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 75. Climbing Stairs

<details>
<summary> View Code </summary>

```cpp
int climbStairs(int n) {
    int prev = 0, cur = 1;
    while (n--) {
        int next = cur + prev;
        prev = cur;
        cur = next;
    }
    return cur;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 76. Shifting Letters II

<details>
<summary> View Code </summary>

```cpp
// Solution 1 - Line Sweep
string shiftingLetters(string s, vector<vector<int>>& shifts) {
    int line[50001] = {};
    for (auto &shift : shifts) {
        line[shift[0]] += shift[2] ? 1 : -1;
        line[shift[1] + 1] += shift[2] ? -1 : 1;
    }
    for (int i = 0, val = 0; i < s.size(); ++i) {
        val = (val + line[i]) % 26;
        s[i] = 'a' + (26 + (s[i] - 'a') + val) % 26;
    }
    return s;
}

// Solution 2 - Fenwick Tree
constexpr int static n = 50000;
int bt[n + 1] = {};
int prefix_sum(int i)
{
    int sum = 0;
    for (i = i + 1; i > 0; i -= i & (-i))
        sum += bt[i];
    return sum;
}
void add(int i, int val)
{
    for (i = i + 1; i <= n; i += i & (-i))
        bt[i] += val;
}
string shiftingLetters(string s, vector<vector<int>>& shifts) {
    for (auto &shift : shifts) {
        add(shift[0], shift[2] == 1 ? 1 : -1);
        add(shift[1] + 1, shift[2] == 1 ? -1 : 1);
    }
    for (int i = 0; i < s.size(); ++i)
        s[i] = 'a' + (26 + (s[i] - 'a') + prefix_sum(i) % 26) % 26;
    return s;
}

// Solution 3 - Segment Tree
class Solution {
public:
    vector<int> seg;

    void upd(int l, int r, int v, int x, int lx, int rx) {
        if(lx > r or rx < l) return;
        if(lx >= l and rx <= r) {
            seg[x] += v;
            return;
        }
        int mid = (lx + rx) / 2;
        upd(l, r, v, 2 * x + 1, lx, mid);
        upd(l, r, v, 2 * x + 2, mid + 1, rx);
    }

    int query(int i, int x, int lx, int rx) {
        if(lx == rx) return seg[x];

        int mid = (lx + rx) / 2;

        if(i <= mid)
            return seg[x] + query(i, 2 * x + 1, lx, mid);

        return seg[x] + query(i, 2 * x + 2, mid + 1, rx);
    }
    
    string shiftingLetters(string s, vector<vector<int>>& shifts) {
        long x = 1;
        while(x <= s.length()) x <<= 1;
        seg.resize(2 * x, 0);
        
        for(int i = 0; i < shifts.size(); ++i) {
            int l = shifts[i][0], r = shifts[i][1], dir;
            if(shifts[i][2] == 0) dir = -1;
            else dir = 1;
            upd(l, r, dir, 0, 0, x - 1);
        }
        
        for(int i = 0; i < s.length(); ++i) {
            int shift = query(i, 0, 0, x - 1);
            int dir = (shift > 0) ? 1 : -1;
            shift = abs(shift) % 26; 
            
            shift *= dir;
            int cur = s[i] - 'a';
            cur = (cur + shift + 26) % 26;
            s[i] = char(cur + 'a');
        }
        return s;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 77. Build A Matrix With Conditions

<details>
<summary> View Code </summary>

```cpp
vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {
	vector<int> order1 = topologicalSort(rowConditions, k);
	vector<int> order2 = topologicalSort(colConditions, k);
	if (order1.size() < k || order2.size() < k) return {};
	unordered_map<int, int> m;
	for (int i = 0; i < k; i++) m[order2[i]] = i;
	vector<vector<int>> ans(k, vector<int>(k, 0));
	for (int i = 0; i < k; i++)
		ans[i][m[order1[i]]] = order1[i];
	return ans;
}
vector<int> topologicalSort(vector<vector<int>> &A, int k) {
	vector<int> deg(k, 0), order;
	vector<vector<int>> graph(k, vector<int>(0));
	queue<int> q;
	for (auto &c: A) {
		graph[c[0] - 1].push_back(c[1] - 1);
		deg[c[1] - 1]++;
	}
	for(int i = 0; i < k; i++) 
		if (!deg[i]) q.push(i);
	while (!q.empty()) {
		int x = q.front(); q.pop();
		order.push_back(x + 1);
		for (int& y: graph[x]) 
			if (--deg[y] == 0) 
				q.push(y);
	}
	return order;
}
```

</details>

<br>[⬆ Back to top](#table-of-contents)


## 78. Serialize and Deserialize Binary Tree

<details>
<summary> View Code </summary>

```cpp
class Codec {
private:
    TreeNode *getNode(vector<string> &v, int &i) {
        string s = v[i++];
        return s == "#" ? NULL : new TreeNode(stoi(s));
    }
public:
    string serialize(TreeNode* root) {
        if (!root) return "";
        queue<TreeNode*> q;
        q.push(root);
        string ans;
        while (!q.empty()) {
            root = q.front();
            q.pop();
            if (!ans.empty()) ans += ',';
            if (root) {
                ans += to_string(root->val);
                q.push(root->left);
                q.push(root->right);
            } else ans += '#';
        }
        return ans;
    }
    TreeNode* deserialize(string data) {
        if (data.empty()) return NULL;
        stringstream ss(data);
        string val;
        vector<string> v;
        while (getline(ss, val, ',')) v.push_back(val);
        TreeNode *root = new TreeNode(stoi(v[0]));
        queue<TreeNode*> q;
        q.push(root);
        int i = 1;
        while (i < v.size()) {
            TreeNode *node = q.front();
            q.pop();
            node->left = getNode(v, i);
            node->right = getNode(v, i);
            if (node->left) q.push(node->left);
            if (node->right) q.push(node->right);
        }
        return root;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 79. Pacific Atlantic Water Flow

<details>
<summary> View Code </summary>

```cpp
class Solution {
    int dirs[4][2] = {{0,1},{0,-1},{1,0},{-1,0}}, M, N;
    void dfs(vector<vector<int>> &A, int x, int y, vector<vector<int>> &m) {
        if (m[x][y]) return;
        m[x][y] = 1;
        for (auto &[dx, dy] : dirs) {
            int a = x + dx, b = y + dy;
            if (a < 0 || a >= M || b < 0 || b >= N || A[a][b] < A[x][y]) continue;
            dfs(A, a, b, m);
        }
    }
public:
    vector<vector<int>> pacificAtlantic(vector<vector<int>>& A) {
        if (A.empty() || A[0].empty()) return {};
        M = A.size(), N = A[0].size();
        vector<vector<int>> a(M, vector<int>(N)), b(M, vector<int>(N)), ans; 
        for (int i = 0; i < M; ++i) {
            dfs(A, i, 0, a);
            dfs(A, i, N - 1, b);
        }
        for (int j = 0; j < N; ++j) {
            dfs(A, 0, j, a);
            dfs(A, M - 1, j, b);
        }
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < N; ++j) {
                if (a[i][j] && b[i][j]) ans.push_back({i, j});
            }
        }
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 80. Delete and Earn

<details>
<summary> View Code </summary>

```cpp
int deleteAndEarn(vector<int>& nums) {
    vector<int> dp(10002, 0);
    vector<int> sum(10002, 0);
    
    for(auto a : nums) {
        sum[a] += a;
    }
    
    dp[0] = sum[0];
    dp[1] = sum[1];
    
    for(int i = 2; i < 10001; i++) {
        dp[i] = max(dp[i - 1], dp[i - 2] + sum[i]);
    }
    
    return dp[10000];
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 81. Permutations II

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> ans;
    void permute(vector<int> nums, int start) {
        if(start == nums.size() - 1) {
            ans.push_back(nums);
            return;
        }
        
        for(int i = start; i < nums.size(); i++) {
            if(i != start && nums[i] == nums[start]) continue;
            swap(nums[i], nums[start]);
            permute(nums, start + 1);
        }
    }
    
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        permute(nums, 0);
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 82. Combination Sum II

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<int>> combinationSum2(vector<int>& A, int target) {
        
        int N = A.size();
        sort(A.begin(), A.end());
        vector<vector<int>> ans;
        vector<int> temp;
        
        function<void(int, int)> dfs = [&](int start, int goal) {
            if(goal == 0) {
                ans.push_back(temp);
                return;
            }
            
            for(int i = start; i < N && goal - A[i] >= 0 ; i++) {
                if(i != start && A[i] == A[i - 1]) continue;
                temp.push_back(A[i]);
                dfs(i + 1, goal - A[i]);
                temp.pop_back();
            }
        };
        
        dfs(0, target);
        
        return ans;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 83. Non Overlapping Intervals

<details>
<summary> View Code </summary>

```cpp
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
    sort(intervals.begin(), intervals.end(), [](auto &a, auto &b) {
        return a[1] < b[1];
    });
    
    int overlapCnt = 0;
    int end = INT_MIN;
    
    for(auto &e : intervals) {
        if(e[0] >= end) {
            end = e[1];
        } else {
            overlapCnt++;
        }
    }
    
    return overlapCnt;
}
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 84. Best Time To Buy and Sell Stocks With Cooldown

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    int maxProfit(vector<int>& A) {
        if (A.empty()) return 0;
        int N = A.size(), buy = INT_MIN;
        vector<int> dp(N + 1, 0);
        for (int i = 0; i < N; ++i) {
            buy = max(buy, (i >= 1 ? dp[i - 1] : 0) - A[i]);
            dp[i + 1] = max(dp[i], buy + A[i]);
        }
        return dp[N];
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 85. Maximum XOR of Two Numbers In An Array

<details>
<summary> Approach </summary>

This algorithm's idea is:
to iteratively determine what would be each bit of the final result from left to right. And it narrows down the candidate group iteration by iteration. e.g. assume input are `a,b,c,d,...z`, `26` integers in total. In first iteration, if you found that `a, d, e, h, u` differs on the MSB(most significant bit), so you are sure your final result's MSB is set. Now in second iteration, you try to see if among `a, d, e, h, u` there are at least two numbers make the 2nd MSB differs, if yes, then definitely, the 2nd MSB will be set in the final result. And maybe at this point the candidate group shinks from `a,d,e,h,u` to `a, e, h`. Implicitly, every iteration, you are narrowing down the candidate group, but you don't need to track how the group is shrinking, you only cares about the final result.

* The mask will grow like  `100..000 , 110..000, 111..000,  then 1111...111` for each iteration, we only care about the left parts.
* We only care about the left parts, for example, if `i = 2`, then we have `{1100, 1000, 0100, 0000}` from `{1110, 1011, 0111, 0010}`.
* If `i = 1`and before this iteration, the maxResult we have now is `1100`, my wish is the maxResult will grow to `1110`, so I will try to find a candidate which can give me the greedyTry.
* This is the most tricky part, coming from a fact that if `a ^ b = c`, then `a ^ c = b`, now we have the `c`, which is greedyTry, and we have the `a`, which is leftPartOfNum. If we hope the formula `a ^ b = c` to be valid, then we need the `b`,  and to get `b`, we need `a ^ c`, if `a ^ c` exisited in our set, then we're good to go.
</details>

<details>
<summary> Solution - Bitmasks </summary>

```cpp
class Solution {
public:
    int findMaximumXOR(vector<int>& A) {
        unordered_set<int> s;
        int mask = 0, ans = 0;
        for (int i = 31; i >= 0; --i) {
            mask |= 1 << i;
            s.clear();
            for (int n : A) s.insert(n & mask);
            int next = ans | (1 << i);
            for (int prefix : s) {
                if (!s.count(next ^ prefix)) continue;
                ans |= 1 << i;
                break;
            }
        }
        return ans;
    }
};

```
</details>

<details>
<summary> Solution - Trie </summary>

```cpp
struct TrieNode {
    TrieNode *next[2] = {};
};
class Solution {
    void add(TrieNode *node, int n) {
        for (int i = 31; i >= 0; --i) {
            int b = n >> i & 1;
            if (node->next[b] == NULL) node->next[b] = new TrieNode();
            node = node->next[b];
        }
    }
    int maxXor(TrieNode *node, int n) {
        int ans = 0;
        for (int i = 31; i >= 0; --i) {
            int b = n >> i & 1;
            if (node->next[1 - b]) { // if we can go the opposite direction, do it.
                node = node->next[1 - b];
                ans |= 1 << i;
            } else {
                node = node->next[b];
            }
        }
        return ans;
    }
public:
    int findMaximumXOR(vector<int>& A) {
        TrieNode root;
        int ans = 0;
        for (int n : A) {
            add(&root, n);
            ans = max(ans, maxXor(&root, n));
        }
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 86. Implement Queue Using Stacks

<details>
<summary> View Code </summary>

```cpp
class MyQueue {
public:
    
    stack<int> S1, S2;
    
    void push(int x) {
        while(!S1.empty()) {
            S2.push(S1.top());
            S1.pop();
        }
        
        S2.push(x);
        
        while(!S2.empty()) {
            S1.push(S2.top());
            S2.pop();
        }
    }
    
    int pop() {
        int x = S1.top();
        S1.pop();
        
        return x;
    }
    
    int peek() {
        return S1.top();
    }
    
    bool empty() {
        return S1.empty();
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)


## 87. Minimum Size Subarray Sum 

<details>
<summary> View Code </summary>

```cpp
int minSubArrayLen(int target, vector<int>& nums) {   
    int N = nums.size();
    int i = 0, sum = 0, ans = INT_MAX;
    
    for(int j = 0; j < N; j++) {
        sum += nums[j];
        
        while(sum >= target) {
            if(sum >= target) {
                ans = min(ans, j - i + 1);
            }
            sum -= nums[i++];
        }  
    }
    
    return ans == INT_MAX ? 0 : ans;
}
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 88. Number of Visible People In A Queue

<details>
<summary> View Code </summary>

```cpp
vector<int> canSeePersonsCount(vector<int>& A) {
    stack<int> S;
    int N = A.size();
    vector<int> ans(N, 0);
    
    for(int i = 0; i < N; i++) {
        // Monotonically Increasing Sequence
        while(S.size() && A[S.top()] <= A[i]) {
            ans[S.top()]++;
            S.pop();
        }
        
        if(S.size()) {
            ans[S.top()]++;
        }
        
        S.push(i);
    }    
    return ans;    
}
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 89. Describe The Painting 

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    vector<vector<long long>> splitPainting(vector<vector<int>>& segments) {
        long long line[200001] = {};
        bool change[200001] = {};
        
        int maxEnd = -1;
        
        for(auto &e : segments) {
            int start = e[0], end = e[1], value = e[2];
            line[start] += value;
            line[end] -= value;
            change[start] = change[end] = true;
            maxEnd = max(maxEnd, end);
        }
        
        for(int i = 1; i <= maxEnd; i++) {
            line[i] += line[i - 1];
        }
        
        vector<vector<long long>> ans;
        
        for(int i = 0; i <= maxEnd;) {
            int start = i;
            while(i <= maxEnd && line[i] == line[start] && (i == start || !change[i])) i++;
            
            if(line[start]) {
                ans.push_back({start, i, line[start]});
            }
        }
        
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top](#table-of-contents)

## 90. Flood Fill

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    int dirs[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    int M, N, startingColor;
    
    void dfs(vector<vector<int>> &image, int x, int y, int C) {
        
        image[x][y] = C;
        
        for(auto &dir : dirs) {
            int a = x + dir[0];
            int b = y + dir[1];
            
            if(a < 0 || b < 0 || a >= M || b >= N || image[a][b] != startingColor) continue;
            
            dfs(image, a, b, C);
        }
    }
    
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        M = image.size();
        N = image[0].size();
        
        startingColor = image[sr][sc];
        
        if(color == startingColor) {
            return image;
        }
        
        dfs(image,  sr, sc, color);
        
        return image;
    }
};
```
</details>

<br>[⬆ Back to top](#table-of-contents)

## 91. Palindrome Partitioning

<details>
<summary> View Code </summary>

```cpp
class Solution {
public:
    
    bool isPalindrome(string &s, int i, int j) {
        while(i < j && s[i] == s[j]) {
            i++;
            j--;
        }
        return i >= j;
    }
    
    vector<vector<string>> ans;
    vector<string> temp;
    
    void dfs(string &s, int start) {
        if(start == s.size()) {
            ans.push_back(temp);
            return;
        }
        
        for(int i = start; i < s.length(); i++) {
            if(!isPalindrome(s, start, i)) continue;
            
            temp.push_back(s.substr(start, i - start + 1));
            dfs(s, i + 1);
            temp.pop_back();
        }
    }
    
    vector<vector<string>> partition(string s) {
        dfs(s, 0);
        return ans;
    }
};
```

</details>

<br>[⬆ Back to top]
Download .txt
gitextract_fbu3irtf/

├── README.md
├── markdown/
│   ├── code-2.md
│   └── code.md
├── random/
│   ├── Random.md
│   └── SOLUTIONS.md
└── solutions/
    ├── base-conversion.md
    ├── bellman-ford.md
    ├── binary-trees.md
    ├── bit-manipulation.md
    ├── custom-comparator.md
    ├── design.md
    ├── dfs.md
    ├── dijksta.md
    ├── dp.md
    ├── euler-circuit.md
    ├── fenwick-tree.md
    ├── heaps/
    │   ├── kth-largest-element-in-array.md
    │   ├── sort-array-by-increasing-frequency.md
    │   ├── sort-characters-by-frequency.md
    │   └── top-k-frequent-elements.md
    ├── intervals.md
    ├── kruskal.md
    ├── line-sweep.md
    ├── linked-list.md
    ├── lis.md
    ├── manacher.md
    ├── matrix.md
    ├── merge-sort.md
    ├── prefix-state-map.md
    ├── queries.md
    ├── rolling-hash/
    │   ├── distinct-echo-substrings.md
    │   ├── find-substring-with-given-hash-value.md
    │   ├── k-divisible-elements-subarray.md
    │   ├── longest-common-subpath.md
    │   ├── longest-duplicate-substring.md
    │   ├── repeated-dna-sequences.md
    │   ├── shortest-palindrome.md
    │   └── sum-of-scores-of-built-strings.md
    ├── segment-tree.md
    ├── sets.md
    ├── sieve-eratosthenes.md
    ├── sliding-window/
    │   └── count-subarrays-with-fixed-count.md
    ├── sliding-window.md
    ├── stack.md
    ├── stringstream.md
    ├── sum-of-first-n-natural-numbers.md
    ├── topological-sort.md
    └── trie/
        ├── concatenated-words.md
        ├── implement-trie.md
        ├── k-divisible-elements-subarrays.md
        ├── maximum-genetic-difference-query.md
        ├── maximum-xor-of-two-numbers.md
        ├── palindrome-pairs.md
        ├── search-suggestions-system.md
        └── sum-of-prefix-scores-of-strings.md
Condensed preview — 55 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (352K chars).
[
  {
    "path": "README.md",
    "chars": 80402,
    "preview": "<div align=\"center\">\n<h1>Awesome Leetcode</h1>\n\n<a href=\"https://github.com/kiranpalsingh1806/awesome-leetcode\"><img src"
  },
  {
    "path": "markdown/code-2.md",
    "chars": 28,
    "preview": "## Heading here\n\n```cpp\n\n```"
  },
  {
    "path": "markdown/code.md",
    "chars": 82,
    "preview": "## Heading here\n\n<details>\n<summary> View Code </summary>\n\n```cpp\n\n```\n\n</details>"
  },
  {
    "path": "random/Random.md",
    "chars": 28798,
    "preview": "# LeetCode Problems\n\n|Index|Problem|Topic|Solution|\n|------|------|--------|------|\n|1|[Longest Increasing Subsequence]("
  },
  {
    "path": "random/SOLUTIONS.md",
    "chars": 160528,
    "preview": "# Table of Contents\n- [Table of Contents](#table-of-contents)\n  - [1. Longest Increasing Subsequence](#1-longest-increas"
  },
  {
    "path": "solutions/base-conversion.md",
    "chars": 620,
    "preview": "# Base Conversion\n\n## Find Unique Binary String\n\n- Conversion of String to Number via stoi()\n- Use of bitset\n\n```cpp\ncla"
  },
  {
    "path": "solutions/bellman-ford.md",
    "chars": 1368,
    "preview": "# Bellman Ford Algorithm\n\n## Cheapest Flights Within K Stops\n\n```cpp\nclass Solution {\npublic:\n    int findCheapestPrice("
  },
  {
    "path": "solutions/binary-trees.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/bit-manipulation.md",
    "chars": 342,
    "preview": "- [Bit Manipulation](#bit-manipulation)\n  - [17. Number of One bits](#17-number-of-one-bits)\n\n# Bit Manipulation\n\n## 17."
  },
  {
    "path": "solutions/custom-comparator.md",
    "chars": 1288,
    "preview": "# Custom Comparator\n\n## Sort Array By Parity\n\n```cpp\nvector<int> sortArrayByParity(vector<int>& nums) {\n    sort(nums.be"
  },
  {
    "path": "solutions/design.md",
    "chars": 2785,
    "preview": "# Design and Implementation\n\n## Implement Queue Using Stack\n\n```cpp\nclass MyQueue {\npublic:\n    stack<int> S1, S2;\n    \n"
  },
  {
    "path": "solutions/dfs.md",
    "chars": 819,
    "preview": "# DFS\n\n## 13. Restore the Array From Adjacent Pairs\n\n```cpp\nclass Solution {\npublic:\n    unordered_map<int, vector<int>>"
  },
  {
    "path": "solutions/dijksta.md",
    "chars": 6170,
    "preview": "- [Dijkstra's Algorithm](#dijkstras-algorithm)\n  - [1. Network Delay Time](#1-network-delay-time)\n  - [2. Cheapest Fligh"
  },
  {
    "path": "solutions/dp.md",
    "chars": 5286,
    "preview": "- [Dynamic Programming](#dynamic-programming)\n  - [Climbing Stairs](#climbing-stairs)\n  - [Pascal's Triangle](#pascals-t"
  },
  {
    "path": "solutions/euler-circuit.md",
    "chars": 2556,
    "preview": "# Euler Circuit\n\n## Reconstruct Itinerary\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass Solution {\npublic:\n   "
  },
  {
    "path": "solutions/fenwick-tree.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/heaps/kth-largest-element-in-array.md",
    "chars": 344,
    "preview": "## Kth Largest Element in Array\n\n```cpp\nclass Solution {\npublic:\n    int findKthLargest(vector<int>& nums, int k) {\n    "
  },
  {
    "path": "solutions/heaps/sort-array-by-increasing-frequency.md",
    "chars": 799,
    "preview": "## Sort Array By Increasing Frequency\n\n```cpp\nclass Solution {\npublic:\n    vector<int> frequencySort(vector<int>& nums) "
  },
  {
    "path": "solutions/heaps/sort-characters-by-frequency.md",
    "chars": 662,
    "preview": "## Sort Characters By Frequency\n\n```cpp\nclass Solution {\npublic:\n    string frequencySort(string s) {\n        \n        u"
  },
  {
    "path": "solutions/heaps/top-k-frequent-elements.md",
    "chars": 731,
    "preview": "## Top K Frequent Elements\n\n```cpp\nclass Solution {\npublic:\n    vector<int> topKFrequent(vector<int>& nums, int k) {\n   "
  },
  {
    "path": "solutions/intervals.md",
    "chars": 3957,
    "preview": "# Intervals\n\n## Merge Intervals\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass Solution {\npublic:\n    vector<ve"
  },
  {
    "path": "solutions/kruskal.md",
    "chars": 3660,
    "preview": "# Kruskal Algorithm\n\n## Min Cost To Connect All Points\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass UnionFind"
  },
  {
    "path": "solutions/line-sweep.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/linked-list.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/lis.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/manacher.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/matrix.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/merge-sort.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/prefix-state-map.md",
    "chars": 2549,
    "preview": "# Prefix State Map\n\n## Contiguous Array\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass Solution {\npublic:\n    i"
  },
  {
    "path": "solutions/queries.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/rolling-hash/distinct-echo-substrings.md",
    "chars": 1227,
    "preview": "## Distinct Echo Substrings\n\n```cpp\nclass Solution {\npublic:\n    int distinctEchoSubstrings(string s) {\n        \n       "
  },
  {
    "path": "solutions/rolling-hash/find-substring-with-given-hash-value.md",
    "chars": 884,
    "preview": "## Find Substring With Given Hash Value\n\n```cpp\nclass Solution {\npublic:\n    string subStrHash(string s, int p, int M, i"
  },
  {
    "path": "solutions/rolling-hash/k-divisible-elements-subarray.md",
    "chars": 722,
    "preview": "## K Divisible Elements Subarray\n\n```cpp\nclass Solution {\npublic:\n    int countDistinct(vector<int>& nums, int k, int p)"
  },
  {
    "path": "solutions/rolling-hash/longest-common-subpath.md",
    "chars": 38,
    "preview": "## Longest Common Subpath\n\n```cpp\n\n```"
  },
  {
    "path": "solutions/rolling-hash/longest-duplicate-substring.md",
    "chars": 44,
    "preview": "## Longest Duplicate Substring \n\n```cpp\n\n```"
  },
  {
    "path": "solutions/rolling-hash/repeated-dna-sequences.md",
    "chars": 668,
    "preview": "## Repeated DNA Sequences\n\n```cpp\nvector<string> findRepeatedDnaSequences(string s) {\n    int N = s.size();\n    unordere"
  },
  {
    "path": "solutions/rolling-hash/shortest-palindrome.md",
    "chars": 432,
    "preview": "## Shortest Palindrome\n\n```cpp\nclass Solution {\npublic:\n    string shortestPalindrome(string s) {\n        unsigned d = 1"
  },
  {
    "path": "solutions/rolling-hash/sum-of-scores-of-built-strings.md",
    "chars": 46,
    "preview": "## Sum of Scores of Built Strings\n\n```cpp\n\n```"
  },
  {
    "path": "solutions/segment-tree.md",
    "chars": 9174,
    "preview": "# Segment Tree\n\n- [Segment Tree](#segment-tree)\n  - [Sum of Even Numbers After Queries](#sum-of-even-numbers-after-queri"
  },
  {
    "path": "solutions/sets.md",
    "chars": 680,
    "preview": "# Sets\n\n## 1. Find All Numbers Disappeared in an Array\n```cpp\nclass Solution {\npublic:\n    vector<int> findDisappearedNu"
  },
  {
    "path": "solutions/sieve-eratosthenes.md",
    "chars": 1274,
    "preview": "# Sieve of Eratosthenes\n\n## Count Primes\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass Solution {\npublic:\n    "
  },
  {
    "path": "solutions/sliding-window/count-subarrays-with-fixed-count.md",
    "chars": 403,
    "preview": "## Count Subarrays With Fixed Count\n\n```cpp\nlong long countSubarrays(vector<int>& A, int minK, int maxK) {\n    long res "
  },
  {
    "path": "solutions/sliding-window.md",
    "chars": 2175,
    "preview": "# Sliding Window\n\n## Longest Substring Without Repeating Characters\n\n```cpp\nint lengthOfLongestSubstring(string s) {\n   "
  },
  {
    "path": "solutions/stack.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/stringstream.md",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "solutions/sum-of-first-n-natural-numbers.md",
    "chars": 891,
    "preview": "## 1. Count Number of Homogenous Substrings\n\n```cpp\nclass Solution {\npublic:\n    int countHomogenous(string s) {\n       "
  },
  {
    "path": "solutions/topological-sort.md",
    "chars": 5141,
    "preview": "# Topological Sort\n\n## Course Schedule\n\n<details>\n<summary> View Code </summary>\n\n```cpp\nclass Solution {\npublic:\n    bo"
  },
  {
    "path": "solutions/trie/concatenated-words.md",
    "chars": 1165,
    "preview": "## Concatenated Words\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[26] = {};\n    bool end = false;\n};\nclass Solution {\n "
  },
  {
    "path": "solutions/trie/implement-trie.md",
    "chars": 829,
    "preview": "## Implement Trie\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[26] = {};\n    bool isWord = false;\n};\n\nclass Trie {\n    \n"
  },
  {
    "path": "solutions/trie/k-divisible-elements-subarrays.md",
    "chars": 662,
    "preview": "## K Divisible Elements Subarray\n\n```cpp\nstruct Trie {\n    unordered_map<int, Trie*> ch;\n    int cnt = 0;\n    int insert"
  },
  {
    "path": "solutions/trie/maximum-genetic-difference-query.md",
    "chars": 1712,
    "preview": "## Maximum Genetic Difference Query\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[2] = {};\n    int cnt = 0;\n};\nclass Solu"
  },
  {
    "path": "solutions/trie/maximum-xor-of-two-numbers.md",
    "chars": 980,
    "preview": "## Maximum XOR of Two Numbers In An Array\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[2] = {};\n};\nclass Solution {\n    "
  },
  {
    "path": "solutions/trie/palindrome-pairs.md",
    "chars": 1834,
    "preview": "## Palindrome Pairs\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[26] = {};\n    int index = -1;\n    vector<int> palindrom"
  },
  {
    "path": "solutions/trie/search-suggestions-system.md",
    "chars": 1462,
    "preview": "## Search Suggestion System\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[26] = {};\n    int index = -1;\n};\n\nvoid add(Trie"
  },
  {
    "path": "solutions/trie/sum-of-prefix-scores-of-strings.md",
    "chars": 1083,
    "preview": "## Sum of Prefix Scores of Strings\n\n```cpp\nstruct TrieNode {\n    TrieNode *next[26] = {};\n    int cnt = 0;\n};\n\nclass Sol"
  }
]

About this extraction

This page contains the full source code of the kiranpalsingh1806/awesome-leetcode GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 55 files (329.4 KB), approximately 90.4k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!