Love Babbar DSA sheet Solution

Array Solution

Complete DS ALGO in 450 Questions First Step to become a SOFTWARE ENGINEER

Love Babbar is a famous Youtuber, a graduate from NSUT Delhi who has also worked as a Software Engineer in Amazon.

Go and check out

DSA Sheet By Love Babbar

ArrayReverse the array
ArrayFind the maximum and minimum element in an array
ArrayFind the “Kth” max and min element of an
ArrayGiven an array which consists of only 0, 1 and 2.
Sort the array without using any sorting algo
ArrayMove all the negative elements to one side of the
ArrayFind the Union and Intersection of the two sorted
ArrayWrite a program to cyclically rotate an array by
Arrayfind Largest sum contiguous Subarray [V. IMP]
ArrayMinimise the maximum difference between heights
ArrayMinimum no. of Jumps to reach end of an array
Arrayfind duplicate in an array of N+1 Integers
ArrayMerge 2 sorted arrays without using Extra space.
ArrayKadane’s Algo [V.V.V.V.V IMP]
ArrayMerge Intervals
ArrayNext Permutation
ArrayCount Inversion
ArrayBest time to buy and Sell stock
Arrayfind all pairs on integer array whose sum is equal
to given number
Arrayfind common elements In 3 sorted arrays
ArrayRearrange the array in alternating positive and
negative items with O(1) extra space
ArrayFind if there is any subarray with sum equal to 0
ArrayFind factorial of a large number
Arrayfind maximum product subarray 
ArrayFind longest coinsecutive subsequence
ArrayGiven an array of size n and a number k, fin all
elements that appear more than ” n/k ” times.
ArrayMaximum profit by buying and selling a share atmost
ArrayFind whether an array is a subset of another array
ArrayFind the triplet that sum to a given value
ArrayTrapping Rain water problem
ArrayChocolate Distribution problem
ArraySmallest Subarray with sum greater than a given
ArrayThree way partitioning of an array around a given
ArrayMinimum swaps required bring elements less equal K
ArrayMinimum no. of operations required to make an array
ArrayMedian of 2 sorted arrays of equal size
ArrayMedian of 2 sorted arrays of different size
StringReverse a String
StringCheck whether a String is Palindrome or not
StringFind Duplicate characters in a string
StringWhy strings are immutable in Java?
StringWrite a Code to check whether one string is a rotation of another
StringWrite a Program to check whether a string is a valid shuffle of two strings or not
StringCount and Say problem
StringWrite a program to find the longest Palindrome in a string.[ Longest palindromic Substring]
StringFind Longest Recurring Subsequence in String
StringPrint all Subsequences of a string.
StringPrint all the permutations of the given string
StringSplit the Binary string into two substring with equal 0’s and 1’s
StringWord Wrap Problem [VERY IMP].
StringEDIT Distance [Very Imp]
StringFind next greater number with same set of digits. [Very Very IMP]
StringBalanced Parenthesis problem.[Imp]
StringWord break Problem[ Very Imp]
StringRabin Karp Algo
StringKMP Algo
StringConvert a Sentence into its equivalent mobile numeric keypad sequence.
StringMinimum number of bracket reversals needed to make an expression balanced.
StringCount All Palindromic Subsequence in a given String.
StringCount of number of given string in 2D character array
StringSearch a Word in a 2D Grid of characters.
StringBoyer Moore Algorithm for Pattern Searching.
StringConverting Roman Numerals to Decimal
StringLongest Common Prefix
StringNumber of flips to make binary string alternate
StringFind the first repeated word in string.
StringMinimum number of swaps for bracket balancing.
StringFind the longest common subsequence between two strings.
StringProgram to generate all possible valid IP addresses from given  string.
StringWrite a program tofind the smallest window that contains all characters of string itself.
StringRearrange characters in a string such that no two adjacent are same
StringMinimum characters to be added at front to make string palindrome
StringGiven a sequence of words, print all anagrams together
StringFind the smallest window in a string containing all characters of another string
StringRecursively remove all adjacent duplicates
StringString matching where one string contains wildcard characters
StringFunction to find Number of customers who could not get a computer
StringTransform One String to Another using Minimum Number of Given Operation
StringCheck if two given strings are isomorphic to each other
StringRecursively print all sentences that can be formed from list of word lists
Searching & SortingFind first and last positions of an element in a sorted array
Searching & SortingFind a Fixed Point (Value equal to index) in a given array
Searching & SortingSearch in a rotated sorted array
Searching & Sortingsquare root of an integer
Searching & SortingMaximum and minimum of an array using minimum number of comparisons
Searching & SortingOptimum location of point to minimize total distance
Searching & SortingFind the repeating and the missing
Searching & Sortingfind majority element
Searching & SortingSearching in an array where adjacent differ by at most k
Searching & Sortingfind a pair with a given difference
Searching & Sortingfind four elements that sum to a given value
Searching & Sortingmaximum sum such that no 2 elements are adjacent
Searching & SortingCount triplet with sum smaller than a given value
Searching & Sortingmerge 2 sorted arrays
Searching & Sortingprint all subarrays with 0 sum
Searching & SortingProduct array Puzzle
Searching & SortingSort array according to count of set bits
Searching & Sortingminimum no. of swaps required to sort the array
Searching & SortingBishu and Soldiers
Searching & SortingRasta and Kheshtak
Searching & SortingKth smallest number again
Searching & SortingFind pivot element in a sorted array
Searching & SortingK-th Element of Two Sorted Arrays
Searching & SortingAggressive cows
Searching & SortingBook Allocation Problem
Searching & SortingEKOSPOJ:
Searching & SortingJob Scheduling Algo
Searching & SortingMissing Number in AP
Searching & SortingSmallest number with atleastn trailing zeroes infactorial
Searching & SortingPainters Partition Problem:
Searching & SortingROTI-Prata SPOJ
Searching & SortingDoubleHelix SPOJ
Searching & SortingSubset Sums
Searching & SortingFindthe inversion count
Searching & SortingImplement Merge-sort in-place
Searching & SortingPartitioning and Sorting Arrays with Many Repeated Entries
LinkedListWrite a Program to reverse the Linked List. (Both Iterative and recursive)
LinkedListReverse a Linked List in group of Given Size. [Very Imp]
LinkedListWrite a program to Detect loop in a linked list.
LinkedListWrite a program to Delete loop in a linked list.
LinkedListFind the starting point of the loop. 
LinkedListRemove Duplicates in a sorted Linked List.
LinkedListRemove Duplicates in a Un-sorted Linked List.
LinkedListWrite a Program to Move the last element to Front in a Linked List.
LinkedListAdd “1” to a number represented as a Linked List.
LinkedListAdd two numbers represented by linked lists.
LinkedListIntersection of two Sorted Linked List.
LinkedListIntersection Point of two Linked Lists.
LinkedListMerge Sort For Linked lists.[Very Important]
LinkedListQuicksort for Linked Lists.[Very Important]
LinkedListFind the middle Element of a linked list.
LinkedListCheck if a linked list is a circular linked list.
LinkedListSplit a Circular linked list into two halves.
LinkedListWrite a Program to check whether the Singly Linked list is a palindrome or not.
LinkedListDeletion from a Circular Linked List.
LinkedListReverse a Doubly Linked list.
LinkedListFind pairs with a given sum in a DLL.
LinkedListCount triplets in a sorted DLL whose sum is equal to given value “X”.
LinkedListSort a “k”sorted Doubly Linked list.[Very IMP]
LinkedListRotate DoublyLinked list by N nodes.
LinkedListRotate a Doubly Linked list in group of Given Size.[Very IMP]
LinkedListCan we reverse a linked list in less than O(n) ?
LinkedListWhy Quicksort is preferred for. Arrays and Merge Sort for LinkedLists ?
LinkedListFlatten a Linked List
LinkedListSort a LL of 0’s, 1’s and 2’s
LinkedListClone a linked list with next and random pointer
LinkedListMerge K sorted Linked list
LinkedListMultiply 2 no. represented by LL
LinkedListDelete nodes which have a greater value on right side
LinkedListSegregate even and odd nodes in a Linked List
LinkedListProgram for n’th node from the end of a Linked List
LinkedListFind the first non-repeating character from a stream of characters
Binary Treeslevel order traversal
Binary TreesReverse Level Order traversal
Binary TreesHeight of a tree
Binary TreesDiameter of a tree
Binary TreesMirror of a tree
Binary TreesInorder Traversal of a tree both using recursion and Iteration
Binary TreesPreorder Traversal of a tree both using recursion and Iteration
Binary TreesPostorder Traversal of a tree both using recursion and Iteration
Binary TreesLeft View of a tree
Binary TreesRight View of Tree
Binary TreesTop View of a tree
Binary TreesBottom View of a tree
Binary TreesZig-Zag traversal of a binary tree
Binary TreesCheck if a tree is balanced or not
Binary TreesDiagnol Traversal of a Binary tree
Binary TreesBoundary traversal of a Binary tree
Binary TreesConstruct Binary Tree from String with Bracket Representation
Binary TreesConvert Binary tree into Doubly Linked List
Binary TreesConvert Binary tree into Sum tree
Binary TreesConstruct Binary tree from Inorder and preorder traversal
Binary TreesFind minimum swaps required to convert a Binary tree into BST
Binary TreesCheck if Binary tree is Sum tree or not
Binary TreesCheck if all leaf nodes are at same level or not
Binary TreesCheck if a Binary Tree contains duplicate subtrees of size 2 or more [ IMP ]
Binary TreesCheck if 2 trees are mirror or not
Binary TreesSum of Nodes on the Longest path from root to leaf node 
Binary TreesCheck if given graph is tree or not.  [ IMP ]
Binary TreesFind Largest subtree sum in a tree
Binary TreesMaximum Sum of nodes in Binary tree such that no two are adjacent 
Binary TreesPrint all “K” Sum paths in a Binary tree
Binary TreesFind LCA in a Binary tree
Binary TreesFind distance between 2 nodes in a Binary tree
Binary TreesKth Ancestor of node in a Binary tree
Binary TreesFind all Duplicate subtrees in a Binary tree [ IMP ]
Binary TreesTree Isomorphism Problem
GreedyActivity Selection Problem
GreedyJob SequencingProblem
GreedyHuffman Coding
GreedyWater Connection Problem
GreedyFractional Knapsack Problem
GreedyGreedy Algorithm to find Minimum number of Coins
GreedyMaximum trains for which stoppage can be provided
GreedyMinimum Platforms Problem
GreedyBuy Maximum Stocks if i stocks can be bought on i-th day
GreedyFind the minimum and maximum amount to buy all N candies
GreedyMinimize Cash Flow among a given set of friends who have borrowed money from each other
GreedyMinimum Cost to cut a board into squares
GreedyCheck if it is possible to survive on Island
GreedyFind maximum meetings in one room
GreedyMaximum product subset of an array
GreedyMaximize array sum after K negations
GreedyMaximize the sum of arr[i]*i
GreedyMaximum sum of absolute difference of an array
GreedyMaximize sum of consecutive differences in a circular array
GreedyMinimum sum of absolute difference of pairs of two arrays
GreedyProgram for Shortest Job First (or SJF) CPU Scheduling
GreedyProgram for Least Recently Used (LRU) Page Replacement algorithm
GreedySmallest subset with sum greater than all other elements
GreedyChocolate Distribution Problem
GreedyDEFKIN -Defense of a Kingdom
GreedyGERGOVIA -Wine trading in Gergovia
GreedyPicking Up Chicks
GreedyCHOCOLA –Chocolate
GreedyARRANGE -Arranging Amplifiers
GreedyK Centers Problem
GreedyMinimum Cost of ropes
GreedyFind smallest number with given number of digits and sum of digits
GreedyRearrange characters in a string such that no two adjacent are same
GreedyFind maximum sum possible equal sum of three stacks
Stacks & Queues Implement Stack from Scratch
Stacks & Queues Implement Queue from Scratch
Stacks & QueuesImplement 2 stack in an array
Stacks & Queuesfind the middle element of a stack
Stacks & QueuesImplement “N” stacks in an Array
Stacks & QueuesCheck the expression has valid or Balanced parenthesis or not.
Stacks & QueuesReverse a String using Stack
Stacks & QueuesDesign a Stack that supports getMin() in O(1) time and O(1) extra space.
Stacks & QueuesFind the next Greater element
Stacks & QueuesThe celebrity Problem
Stacks & QueuesArithmetic Expression evaluation
Stacks & QueuesEvaluation of Postfix expression
Stacks & QueuesImplement a method to insert an element at its bottom without using any other data structure.
Stacks & QueuesReverse a stack using recursion
Stacks & QueuesSort a Stack using recursion
Stacks & QueuesMerge Overlapping Intervals
Stacks & QueuesLargest rectangular Area in Histogram
Stacks & QueuesLength of the Longest Valid Substring
Stacks & QueuesExpression contains redundant bracket or not
Stacks & QueuesImplement Stack using Queue
Stacks & QueuesImplement Stack using Deque
Stacks & QueuesStack Permutations (Check if an array is stack permutation of other)
Stacks & QueuesImplement Queue using Stack  
Stacks & QueuesImplement “n” queue in an array
Stacks & QueuesImplement a Circular queue
Stacks & QueuesLRU Cache Implementationa
Stacks & QueuesReverse a Queue using recursion
Stacks & QueuesReverse the first “K” elements of a queue
Stacks & QueuesInterleave the first half of the queue with second half
Stacks & QueuesFind the first circular tour that visits all Petrol Pumps
Stacks & QueuesMinimum time required to rot all oranges
Stacks & QueuesDistance of nearest cell having 1 in a binary matrix
Stacks & QueuesFirst negative integer in every window of size “k”
Stacks & QueuesCheck if all levels of two trees are anagrams or not.
Stacks & QueuesSum of minimum and maximum elements of all subarrays of size “k”.
Stacks & QueuesMinimum sum of squares of character counts in a given string after removing “k” characters.
Stacks & QueuesQueue based approach or first non-repeating character in a stream.
Stacks & QueuesNext Smaller Element
GraphCreate a Graph, print it
GraphImplement BFS algorithm 
GraphImplement DFS Algo 
GraphDetect Cycle in Directed Graph using BFS/DFS Algo 
GraphDetect Cycle in UnDirected Graph using BFS/DFS Algo 
GraphSearch in a Maze
GraphMinimum Step by Knight
Graphflood fill algo
GraphClone a graph
GraphMaking wired Connections
Graphword Ladder 
GraphDijkstra algo
GraphImplement Topological Sort 
GraphMinimum time taken by each job to be completed given by a Directed Acyclic Graph
GraphFind whether it is possible to finish all tasks or not from given dependencies
GraphFind the no. of Isalnds
GraphGiven a sorted Dictionary of an Alien Language, find order of characters
GraphImplement Kruksal’sAlgorithm
GraphImplement Prim’s Algorithm
GraphTotal no. of Spanning tree in a graph
GraphImplement Bellman Ford Algorithm
GraphImplement Floyd warshallAlgorithm
GraphTravelling Salesman Problem
GraphGraph ColouringProblem
GraphSnake and Ladders Problem
GraphFind bridge in a graph
GraphCount Strongly connected Components(Kosaraju Algo)
GraphCheck whether a graph is Bipartite or Not
GraphDetect Negative cycle in a graph
GraphLongest path in a Directed Acyclic Graph
GraphJourney to the Moon
GraphCheapest Flights Within K Stops
GraphOliver and the Game
GraphWater Jug problem using BFS
GraphWater Jug problem using BFS
GraphFind if there is a path of more thank length from a source
GraphMinimum edges to reverse o make path from source to destination
GraphPaths to travel each nodes using each edge(Seven Bridges)
GraphVertex Cover Problem
GraphChinese Postman or Route Inspection
GraphNumber of Triangles in a Directed and Undirected Graph
GraphMinimise the cashflow among a given set of friends who have borrowed money from each other
GraphTwo Clique Problem
Dynamic ProgrammingCoin ChangeProblem
Dynamic ProgrammingKnapsack Problem
Dynamic ProgrammingBinomial CoefficientProblem
Dynamic ProgrammingPermutation CoefficientProblem
Dynamic ProgrammingProgram for nth Catalan Number
Dynamic ProgrammingMatrix Chain Multiplication 
Dynamic ProgrammingEdit Distance
Dynamic ProgrammingSubset Sum Problem
Dynamic ProgrammingFriends Pairing Problem
Dynamic ProgrammingGold Mine Problem
Dynamic ProgrammingAssembly Line SchedulingProblem
Dynamic ProgrammingPainting the Fenceproblem
Dynamic ProgrammingMaximize The Cut Segments
Dynamic ProgrammingLongest Common Subsequence
Dynamic ProgrammingLongest Repeated Subsequence
Dynamic ProgrammingLongest Increasing Subsequence
Dynamic ProgrammingSpace Optimized Solution of LCS
Dynamic ProgrammingLCS (Longest Common Subsequence) of three strings
Dynamic ProgrammingMaximum Sum Increasing Subsequence
Dynamic ProgrammingCount all subsequences having product less than K
Dynamic ProgrammingLongest subsequence such that difference between adjacent is one
Dynamic ProgrammingMaximum subsequence sum such that no three are consecutive
Dynamic ProgrammingEgg Dropping Problem
Dynamic ProgrammingMaximum Length Chain of Pairs
Dynamic ProgrammingMaximum size square sub-matrix with all 1s
Dynamic ProgrammingMaximum sum of pairs with specific difference
Dynamic ProgrammingMin Cost PathProblem
Dynamic ProgrammingMaximum difference of zeros and ones in binary string
Dynamic ProgrammingMinimum number of jumps to reach end
Dynamic ProgrammingMinimum cost to fill given weight in a bag
Dynamic ProgrammingMinimum removals from array to make max –min <= K
Dynamic ProgrammingLongest Common Substring
Dynamic ProgrammingCount number of ways to reacha given score in a game
Dynamic ProgrammingCount Balanced Binary Trees of Height h
Dynamic ProgrammingLargestSum Contiguous Subarray [V>V>V>V IMP ]
Dynamic ProgrammingSmallest sum contiguous subarray
Dynamic ProgrammingUnbounded Knapsack (Repetition of items allowed)
Dynamic ProgrammingWord Break Problem
Dynamic ProgrammingLargest Independent Set Problem
Dynamic ProgrammingPartition problem
Dynamic ProgrammingLongest Palindromic Subsequence
Dynamic ProgrammingCount All Palindromic Subsequence in a given String
Dynamic ProgrammingLongest Palindromic Substring
Dynamic ProgrammingLongest alternating subsequence
Dynamic ProgrammingWeighted Job Scheduling
Dynamic ProgrammingCoin game winner where every player has three choices
Dynamic ProgrammingCount Derangements (Permutation such that no element appears in its original position) [ IMPORTANT ]
Dynamic ProgrammingMaximum profit by buying and selling a share at most twice [ IMP ]
Dynamic ProgrammingOptimal Strategy for a Game
Dynamic ProgrammingOptimal Binary Search Tree
Dynamic ProgrammingPalindrome PartitioningProblem
Dynamic ProgrammingWord Wrap Problem
Dynamic ProgrammingMobile Numeric Keypad Problem [ IMP ]
Dynamic ProgrammingBoolean Parenthesization Problem
Dynamic ProgrammingLargest rectangular sub-matrix whose sum is 0
Dynamic ProgrammingLargest area rectangular sub-matrix with equal number of 1’s and 0’s [ IMP ]
Dynamic ProgrammingMaximum sum rectangle in a 2D matrix
Dynamic ProgrammingMaximum profit by buying and selling a share at most k times
Dynamic ProgrammingFind if a string is interleaved of two other strings
Dynamic ProgrammingMaximum Length of Pair Chain

Extra Feature Of This Website Click Icons

PrepInsta Top 100 Codes
These codes are very important since these will help you clear your basic concepts in various languages.
Striver’s SDE Sheet – Top Coding Interview Problems.
Check out the Most Asked Coding Interview Problem list compiled .
DSA alg by Love Babbar
Sheet With solution
$ code
Love Babbar is a famous Youtuber, a graduate from NSUT Delhi who has also worked as a Software Engineer in Amazon.
Go and subscribe My Channel for more updates.
Add Your Heading Text HereIf you follow my website, then there will be improvement in your coding skills and you will get success.

1 thought on “DS Algo sheet by Love Babbar with Solution”

Leave a Reply

Your email address will not be published. Required fields are marked *