I have solved quite number of problems from GFG, Leetcode and in other platforms, in this repository i will be sharing solution to some important question to build command over Data Structure and Algorithm, the solution to problems are highly optimised and concise. This repository can be used as help for those who are new to competitive programming. The code is merely a snippet (as solved on GFG) & hence is not executable in a c++ compiler.
- Array
- String
- Linked List
- Stack and Queue
- Binary Tree
- Binary Search Tree
- Heap
- Hashing
- Graph
- Greedy
- Divide and Conquer
- Backtracking
- Dynamic Programming
- Sliding Window
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Count pairs with given sum | Solution | Easy | |||
2 | Find Missing And Repeating | Solution | O(n) | O(1) | Medium | 🌟 |
3 | Merge Without Extra Space | Solution | Hard | |||
4 | Container With Most Water | Solution | O(n) | O(1) | Medium | |
5 | Count Primes | Solution | O(n) | O(n) | Easy | Sieve of Eratosthenes |
6 | Sort an array of 0s, 1s and 2s | Solution | O(n) | O(1) | Medium | |
7 | Kth Largest Element in an Array | Solution | O(n) | O(1) | Medium | Quickselect |
8 | First Missing Positive | Solution | O(n) | O(1) | Hard | |
18 | Maximum Product Subarray | Solution | O(n) | O(1) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Array to BST | Solution | O(n) | O(n) | Easy | |
2 | Insert a node in a BST | Solution | O(n) | O(n) | Easy | |
3 | Lowest Common Ancestor in a BST | Solution | O(n) | O(n) | Easy | |
4 | Inorder Successor in BST | Solution | O(H) | O(1) | Easy | |
5 | Delete a node from BST | Solution | O(H) | O(H) | Medium | |
6 | Check for BST | Solution | O(n) | O(H) | Medium | |
7 | Merge Two Binary Trees | Solution | O(n) | O(n) | Medium | |
8 | Largest BST | Solution | O(n) | O(H) | Medium | |
9 | Balance a Binary Search Tree | Solution | O(n) | O(n) | Medium | |
10 | Maximum Sum BST in Binary Tree | Solution | O(n) | O(H) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Find median in a stream | Solution | O(nlogn) | O(n) | Hard | |
2 | *Huffman Encoding | Solution | O(nlogn) | O(n) | Medium | |
3 | *Merge k Sorted Arrays | Solution | O(nklogk) | O(n) | Medium | |
4 | *Merge K sorted linked lists | Solution | O(nklogk) | O(n) | Medium | |
5 | Minimum Cost of ropes | Solution | O(nlogn) | O(n) | Medium | |
6 | Reorganize String | Solution | O(nlogn) | O(n) | Medium | |
7 | Kth largest element in a stream | Solution | O(nlogk) | O(n) | Medium | |
8 | *Is Binary Tree Heap | Solution | O(n) | O(n) | Easy | |
9 | Binary Heap Operations | Solution | O(Q*H ) | O(1) | Easy | |
10 | Heap Sort | Solution | O(nlogn) | O(1) | Easy | |
11 | Huffman Decoding | Solution | O(n) | O(n) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Relative Sorting | Solution | O(nlogn) | O(n) | Medium | |
2 | Longest Consecutive Sequence | Solution | O(n) | O(n) | Medium | |
3 | Sorting Elements of an Array by Frequency | Solution | O(nlogn) | O(n) | Medium | |
4 | Longest Substring Without Repeating Characters | Solution | O(n) | O(n) | Medium | 🌟 |
5 | Partition Labels | Solution | O(n) | O(n) | Medium | |
6 | Longest Sub-Array with Sum K | Solution | O(n) | O(n) | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | *Water Connection Problem | Solution | O(n) | O(n) | Medium | |
2 | Coin Piles | Solution | O(n^2) | O(n) | Medium | |
3 | Minimum Platforms | Solution | O(nlogn) | O(n) | Medium | |
4 | Minimize the heights | Solution | O(nlogn) | O(n) | Medium | |
5 | Job Sequencing Problem | Solution | O(n^2) | O(n) | Medium | |
6 | Activity Selection | Solution | O(nlogn) | O(n) | Easy | |
7 | *Minimum Swaps for Bracket Balancing | Solution | O(n) | O(n) | Easy |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Binary Search | Solution | O(logn) | O(1) | Basic | |
2 | Merge Sort | Solution | O(nlogn) | O(n) | Easy | |
3 | Quick Sort | Solution | O(nlogn) | O(n) | Easy | |
4 | Search in a Rotated Array | Solution | O(logn) | O(n) | Easy | |
5 | Modular Exponentiation for large numbers | Solution | O(logn) | O(n) | Medium | |
6 | The Nth Fibonnaci | Solution | O(logn) | O(n) | Easy | |
7 | Largest-prime-factor | Solution | Medium |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Combination Sum | Solution | Medium | |||
2 | Combination Sum - 2 | Solution | Medium | |||
3 | Solve the Sudoku | Solution | O(9^(n^2)) | O(n^2) | Hard |
# | Title | Solution | Time | Space | Difficulty | Tag |
---|---|---|---|---|---|---|
1 | Minimum Window Substring | Solution | O(n) | O(n) | Hard | Variable Size SW |
2 | Longest Substring Without Repeating Characters | Solution | O(n) | O(n) | Medium | Variable Size SW |
3 | Pick Toys | Solution | O(n) | O(n) | Medium | Variable Size SW |
4 | Longest K unique characters substring | Solution | O(n) | O(n) | Easy | Variable Size SW |
5 | Sliding Window Maximum | Solution | O(n) | O(k) | Hard | Fixed Size SW |
6 | Count Occurences of Anagrams | Solution | O(n) | O(k) | Medium | Fixed Size SW |
7 | First negative in every window of size k | Solution | O(n) | O(k) | Easy | Fixed Size SW |
8 | Max Sum Subarray of size K | Solution | O(n) | O(1) | Basic | Fixed Size SW |
1. Fork the repository
2. Do the desired changes (add/delete/modify)
3. Make a pull request
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
👤 Ankit Sharma