Implementation of Deque using Doubly Linked List

Problem Statement The problem “Implementation of Deque using Doubly Linked List” states that you need to implement the following functions of Deque or Doubly Ended Queue using a doubly linked list, insertFront(x) : Add element x at the starting of Deque insertEnd(x) : Add element x at the end of …

Read moreImplementation of Deque using Doubly Linked List

Iterative Method to find Height of Binary Tree

Problem Statement The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree The height of a tree …

Read moreIterative Method to find Height of Binary Tree

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

Implement a stack using single queue

Problem Statement The problem “Implement a stack using single queue” asks us to implement a stack (LIFO) data structure using a queue (FIFO) data structure. Here LIFO means Last In First Out while FIFO means First In First Out. Example push(10) push(20) top() pop() push(30) pop() top() Top : 20 …

Read moreImplement a stack using single queue

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

Check if all levels of two Binary Tree are anagrams or not

Problem Statement The problem “Check if all levels of two Binary Tree are anagrams or not” says that you are given two Binary Trees, check if all the levels of the two trees are anagrams or not. Examples Input true Input false Algorithm to Check if all levels of two …

Read moreCheck if all levels of two Binary Tree are anagrams or not

Minimum sum of squares of character counts in a given string after removing k characters

Problem Statement The problem “Minimum sum of squares of character counts in a given string after removing k characters” states that you are given a string containing lower case characters only. You are allowed to remove k characters from the string such that in the remaining string the sum of …

Read moreMinimum sum of squares of character counts in a given string after removing k characters

First negative integer in every window of size k

Problem Statement The problem “First negative integer in every window of size k” states that you are given an array containing positive and negative integers, for every window of size k print the first negative integer in that window. If there is no negative integer in any window then output …

Read moreFirst negative integer in every window of size k