Algo-Data-Structure
Curated list of Algorithms and Data Structure Programs
Maths
- Check if a number is a prime number && Blog
- Given a perfect square. Find the square root(using Linear search and Binary search)
- Find number of pairs in an integer array A whose sum is divisible by M
- Given an array of size N of all distinct integers from 0 to N-1. Rearrange the array such that A[i] = A[A[i]] && Blog
- Find GCD of two numbers
- Check if there exists any subsequence in the array such that gcd(subsequence) == 1
- Find all prime numbers from 1 to N (sieve of eratosthenes)
- Find smallest prime factor for all numbers till N
- Count number of divisors of N
Combinatorics
Bit Manipulation
- Convert a Decimal number to Binary
- Add Binary Strings
- In an array, every element appears thrice except one. Find the single number
- Given an array of N elements. Calculate the sum of xor of all the pairs
- Given an array of N elements. Return max(A[i]&A[j]) where i != j the pairs
Array and Subarray
- Given an array of size N. Find the maximum sum of subarray of length K
- Given an array. Return the sum of all possible subarrays
- Given an array and Q queries. In every query you get start and end index of a subarray. Print the sum of the subarray for every query
- Find majority element in an array (occurring more than n/2 times)
- Find maximum sum of contagious elements (Kadane's Algorithm)
- Return true if subarray from L to R is increasing
2D - Matrix
- Print all diagonals from Right to Left in 2D Matrix
- Print Upper Triangle in a square matrix
- Given a square matrix. Convert it to its transpose without using any extra space
- Given a square matrix. Rotate it by 90 degree in clockwise direction without using any extra space
- Given top left and bottom right indices. Calculate sum of the sub matrix
- Find maximum sum of any submatrix
- Find sum of all submatrices
String
Hashing
- Given an array of N elements. Count the number of duplicate pairs i. e. A[i] == A[j], i != j
- Given an array of size N. Return the minimum distance b/w any two duplicate elements
- Return number of subarrays with sum = 0
- Find the length of the longest set of consecutive elements
Recursion
Linked List
- Doubly Circular Linked List | Detailed Explanation
- Doubly Linked List | Detailed Explanation
- Linked List containing Loop | Detailed Explanation
- Merge Sorted Linked List | Detailed Explanation
- Move Even numbers before Odd | Detailed Explanation
- Reverse Linked List (recusrive and iterative) | Detailed Explanation
- Singly Linked List | Detailed Explanation
- Split Circular Linked List | Detailed Explanation
- Stack using Linked List
- Swap node links in Linked List
- Given a LL, sorted in ascending order. Insert a value maintaing the sorted order
- Reverse first k nodes of a LL
- Find middle node
- Sort LL using merge sort
- Given sorted Doubly LL of unique integers. Count number of pairs of node whose sum of value is equal to k.
- Clone (Deep copy) a LL with random pointer
- Find intersection point of two LLs
Stacks
- Remove Adjacent Duplicates using Stack
- Stack using Array
- Stack using Linked List
- Get minimum value from stack
- Sort the array using Stack
- Double characters trouble
- Nearest Smallest Element
- Largest Rectangle Area in Histogram
- Find sum of max-min for every subarray
- Postfix Notation
Queue and Deque
- Queue using Array
- Queue using Stack
- Return an array containg the max value of every windows of size k
Binary Tree
- Binary Tree
- Height of Binary Tree
- Level Order Traversal
- Vertical Order Traversal
- Given the preorder and inorder traversal of a tree with no duplicates. Contruct the tree
- Left View of Binary Tree
- Right View of Binary Tree
- Return true if the given tree is Height Balanced Tree
- Check Valid Binary Search Tree
- Insert value in a Binary Search Tree
- Delete value from a Binary Search Tree
- Delete every node which has a value outside the range [l, h]
- Given a BST where two nodes have been swapped. Fix the BST
- Iterative Inorder Traversal of BST
- Morris Inorder Traversal of BST
- Diameter of a BT
- Find path from given node to root node in BT
- Calculate number of nodes a a distance k from source node
Binary Search Tree
Subsets and Subsequences
Sorting
- Counting Sort
- Heapsort C++ | Python | Detailed Explanation
- Maximum Priority Queue
- Insertion Sort C++ | Python | Detailed Explanation
- Merge Sort C++ | Python | Detailed Explanation
- Quick Sort C++ | Python | Detailed Explanation
- Selection Sort C++ | Python | Detailed Explanation
- Find total pairs (i, j) such that i < j && A[i] > A[j]
Binary Search
- Given sorted array in ascending order. Find floor of given target k
- Given sorted array in ascending order. Find freq of given target k
- Given array of distince elements. Find any one local minima
- Given array of distinct elements which is sorted then rotated. Find index of target K in this array
- Given an array of positive numbers. Find maximum length K, such that there is no subarray of length K with sum >= B
- Aggresive Cows
- Find Kth position element
- Find Kth position element in two sorted arrays
Pattern Matching
- Given a string of length N. Return LPS array
- Count all permutations of string A in another string B
- Given a text of length N and a pattern of length M. Check if the pattern exists in the text. (N >> M)
- Given a string. Find number of end-start rotation giving the same string
Tries
Heaps
Two Pointers
Greedy Algorithm
Dynamic Programming
- Given N stairs. Count the number of ways of going from 0th to nth step
- Num of ways to get sum from a dice roll
- Given a number K. Find the minimum number of perfect square needed to get the sum K
- House Robbers
- Ways to Decode
- Num of Paths in 2D Matrix
- Dungeon Princess
- Longest Common Subsequence
- Convert s1 to s2 in minimum cost
- Wildcard Matching
- Count num of unique ways in which we can create B as a subseq of A
- Longest Palindromic Subsequence
- 0/1 Knapsack
- 0/infinity Knapsack
- Coin Change Problem
- Equal Array Partitioning
- Minimum Absoulte Difference
- Longest Increasing Subsequence
Graph Algorithms
- Bellman Ford | Detailed Explanation
- Breadth First Search | Detailed Explanation
- BFS - Shortest Path
- BFS - Minimum distance from Hospital for every house
- Depth First Seacrh | Detailed Explanation
- DFS - Count the number of connected components
- DFS - Conflicted Area
- Topological Sort
- Dijkstra Algorithm | Detailed Explanation
- Kruskal Algorithm | Detailed Explanation
Also check out :
CodinGame-Solutions
Competitive-Programming
If you are considering enrolling in Scaler Academy and would like a referral and discount on your fees, I can help. As a current Scaler student, I am able to provide referrals. Please fill out the form at the following link for more information: FORM - Information before Scaler Academy Referral
Are you passionate about development and want to find a job that utilizes your skills? Check out Geektrust for resources and opportunities in the field of development