Cheat Sheet - PLC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Cheat-Sheet

NOTE: Click on topic to get more information.

Array:

Reverse the array


Find the maximum and minimum element in an array
Find the "Kth" max and min element of an array
find Largest sum contiguous Subarray [M. IMP]
Minimise the maximum difference between heights [M.IMP]
Kadane's Algo [M. IMP]
Merge Intervals
Next Permutation
Find factorial of a large number
find maximum product subarray
Find longest consecutive subsequence
Minimum swaps required bring elements less equal K together
Minimum no. of operations required to make an array palindrome

Matrix:
Spiral traversal on a Matrix
Search an element in a matrix
Find median in a row wise sorted matrix
Find row with maximum no. of 1's
Print elements in sorted order using row-column wise sorted matrix
Maximum size rectangle
Find a specific pair in matrix

String:
Reverse a String
Check whether a String is Palindrome or not
Find Duplicate characters in a string
Write a program to find the longest Palindrome in a string.[ Longest palindromic
Substring]
Find next greater number with same set of digits. [M.IMP]
Balanced Parenthesis problem.[Imp]
Rabin Karp Algo
KMP Algo
Convert a Sentence into its equivalent mobile numeric keypad sequence.
Find the smallest window in a string containing all characters of another string
Check if two given strings are isomorphic to each other
Recursively print all sentences that can be formed from list of word lists

Searching & Sorting:


Find first and last positions of an element in a sorted array
Find a Fixed Point (Value equal to index) in a given array
Search in a rotated sorted array
Maximum and minimum of an array using minimum number of comparisons
Optimum location of point to minimize total distance
Find the repeating and the missing
merge 2 sorted arrays
print all subarrays with 0 sum
Product array Puzzle
Sort array according to count of set bits
minimum no. of swaps required to sort the array
Job Scheduling Algo
Missing Number in AP
Implement Merge-sort in-place

Linked List:
Write a Program to reverse the Linked List. (Both Iterative and recursive)
Reverse a Linked List in group of Given Size. [M.IMP]
Write a program to Detect loop in a linked list.
Remove Duplicates in a sorted Linked List.
Remove Duplicates in a Un-sorted Linked List.
Write a Program to Move the last element to Front in a Linked List.
Add “1” to a number represented as a Linked List.
Add two numbers represented by linked lists.
Merge Sort For Linked lists.[M. IMP]
Quicksort for Linked Lists.[M. IMP]
Find the middle Element of a linked list.
Check if a linked list is a circular linked list.
Split a Circular linked list into two halves.
Reverse a Doubly Linked list.
Rotate a Doubly Linked list in group of Given Size.[M. IMP]
Flatten a Linked List
Find the first non-repeating character from a stream of characters
Can we reverse a linked list in less than O(n) ?
Why Quicksort is preferred for Arrays and Merge Sort for Linked-Lists ?

Binary Trees:
level order traversal
Reverse Level Order traversal
Height of a tree
In-order Traversal of a tree both using recursion and Iteration
Pre-order Traversal of a tree both using recursion and Iteration
Post-order Traversal of a tree both using recursion and Iteration
Left View of a tree
Right View of Tree
Top View of a tree
Bottom View of a tree
Check if a tree is balanced or not
Check if a Binary Tree contains duplicate subtrees of size 2 or more [ IMP ]
Check if given graph is tree or not. [ IMP ]
Tree Isomorphism Problem

Binary Search Trees:


Find a value in a BST
Deletion of a node in a BST
Find min and max value in a BST
Find in-order successor and in-order predecessor in a BST
Check if a tree is a BST or not
Populate In-order successor of all nodes
Find LCA of 2 nodes in a BST
Construct BST from pre-order traversal
Convert Binary tree into BST
Merge two BST [M. IMP ]
Find Kth largest element in a BST
Find Kth smallest element in a BST
Largest BST in a Binary Tree [M. IMP ]
Flatten BST to sorted list
Convert a normal BST into a Balanced BST

Greedy:
Activity Selection Problem
Job Sequencing Problem
Huffman Coding
Water Connection Problem
Fractional Knapsack Problem
Greedy Algorithm to find Minimum number of Coins
Maximum trains for which stoppage can be provided
Minimum Platforms Problem
Find the minimum and maximum amount to buy all N candies
Minimize Cash Flow among a given set of friends who have borrowed money from
each other
Minimum Cost to cut a board into squares
Maximize the sum of arr[i]*i
Program for Shortest Job First (or SJF) CPU Scheduling
Program for Least Recently Used (LRU) Page Replacement algorithm
Smallest subset with sum greater than all other elements
Chocolate Distribution Problem
Find smallest number with given number of digits and sum of digits
Rearrange characters in a string such that no two adjacent are same
Find maximum sum possible equal sum of three stacks

Back-Tracking:
Printing all solutions in N-Queen Problem
Word Break Problem using Backtracking
Remove Invalid Parentheses
Sudoku Solver
Find Maximum number possible by doing at-most K swaps
Print all permutations of a string
Find if there is a path of more than k length from a source
Print all possible paths from top left to bottom right of a mXn matrix

Stacks & Queues:


Implement Stack from Scratch
Implement Queue from Scratch
Implement 2 stack in an array
find the middle element of a stack
Implement "N" stacks in an Array
Check the expression has valid or Balanced parenthesis or not.
Reverse a String using Stack
Design a Stack that supports getMin() in O(1) time and O(1) extra space.
Arithmetic Expression evaluation
Evaluation of Postfix expression
Implement a method to insert an element at its bottom without using any other data
structure.
Reverse a stack using recursion
Sort a Stack using recursion
Merge Overlapping Intervals
Implement Stack using Queue
Implement Stack using Deque
Stack Permutations (Check if an array is stack permutation of other)
Implement Queue using Stack
Implement "n" queue in an array
Implement a Circular queue
LRU Cache Implementation
Reverse a Queue using recursion
Reverse the first “K” elements of a queue
Next Smaller Element

Heap:
Implement a Maxheap/MinHeap using arrays and recursion.
Sort an Array using heap. (HeapSort)
Maximum of all subarrays of size k.
“k” largest element in an array
Kth smallest and largest element in an unsorted array
Merge “K” sorted arrays. [ IMP ]
Merge 2 Binary Max Heaps
Check if a Binary Tree is Heap
Convert BST to Min Heap
Convert min heap to max heap
Minimum sum of two numbers formed from digits of an array

Graph:
Create a Graph, print it
Implement BFS algorithm
Implement DFS Algo
Detect Cycle in Directed Graph using BFS/DFS Algo
Detect Cycle in UnDirected Graph using BFS/DFS Algo
Dijkstra algo
Implement Topological Sort
Minimum time taken by each job to be completed given by a Directed Acyclic Graph
Find whether it is possible to finish all tasks or not from given dependencies
Implement Kruskal’s Algorithm
Implement Prim’s Algorithm
Total no. of Spanning tree in a graph
Travelling Salesman Problem
Longest path in a Directed Acyclic Graph
Minimum edges to reverse o make path from source to destination

Trie:
Construct a trie from scratch
Find shortest unique prefix for every word in a given list
Word Break Problem | (Trie solution)
Given a sequence of words, print all anagrams together
Implement a Phone Directory
Print unique rows in a given boolean matrix

Dynamic Programming:
Coin Change Problem
Knapsack Problem
Binomial Coefficient Problem
Permutation Coefficient Problem
Matrix Chain Multiplication
Longest Common Subsequence
Space Optimized Solution of LCS
LCS (Longest Common Subsequence) of three strings
Longest Common Substring
Largest Sum Contiguous Subarray [M. IMP ]
Weighted Job Scheduling

Bit Manipulation:
Count set bits in an integer
Find the two non-repeating elements in an array of repeating elements
Count number of bits to be flipped to convert A to B
Count total set bits in all numbers from 1 to n
Find position of the only set bit
Divide two integers without using multiplication, division and mod operator
Calculate square of a number without using *, / and pow()
Power Set

You might also like