Best Time to Buy and Sell Stock

Problem Statement The problem “Best Time to Buy and Sell Stock” states that you are given an array of prices of length n, where the ith element stores the price of stock on ith day. If we can make only one transaction, that is, to buy on one day and …

Read moreBest Time to Buy and Sell Stock

Level order traversal using two Queues

Problem Statement The problem “Level order traversal using two Queues” states that you are given a binary tree, print its level order traversal line by line. Examples Input 5 11 42 7 9 8 12 23 52 3 Input 1 2 3 4 5 6 Algorithm for Level Order Traversal …

Read moreLevel order traversal using two Queues

Find the First Circular Tour that visits all the Petrol Pumps

Problem Statement The problem “Find the First Circular Tour that visits all the Petrol Pumps” states that there are N petrol pumps on a circular road. Given the petrol that every petrol pump has and the amount of petrol required to cover the distance between two petrol pumps. So you …

Read moreFind the First Circular Tour that visits all the Petrol Pumps

Maximum Product Subarray

Problem Statement The problem “Maximum Product Subarray” states that you are given an array of integer containing both positive and negative numbers. The problem statement asks to find out the maximum product of the sub-array. Example arr[] = { 2, -2, 3, 5} 15 Explanation The elements in the sub-array …

Read moreMaximum Product Subarray

Find Minimum In Rotated Sorted Array

Problem Statement “Find Minimum In Rotated Sorted Array” states that you are given a sorted array of size n which is rotated at some index. Find the minimum element in the array. Example a[ ] = {5, 1, 2, 3, 4} 1 Explanation: If we arrange the array in sorted …

Read moreFind Minimum In Rotated Sorted Array

Iterative method to find ancestors of a given binary tree

Problem Statement “Iterative method to find ancestors of a given binary tree” problem states that you are given a binary tree and an integer representing a key. Create a function to print all the ancestors of the given key using iteration. Example Input¬† key = 6 5 2 1 Explanation: …

Read moreIterative method to find ancestors of a given binary tree

Reverse words in a string

Problem Statement “Reverse words in a string” states that you are given a string s of size n. Print the string in reverse order such that the last word becomes the first, second last becomes the second, and so on. Hereby string we refer to a sentence containing words instead …

Read moreReverse words in a string

Minimum number of jumps to reach end

Problem Statement Suppose you have an array of integers and each element of an array indicates each number as maximum jumps that can be taken from that point. Your task is to find out the minimum number of jumps to reach end, i.e. minimum of jumps that can be taken …

Read moreMinimum number of jumps to reach end