Print Nodes in Top View of Binary Tree

Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a binary tree, print… Read More »

Deque | Set 1 (Introduction and Applications)

Deque or Double Ended Queue is a generalized version of Queue data structure that allows insert and delete at both ends. Operations on Deque: Mainly… Read More »

How to efficiently implement k Queues in a single array?

We have discussed efficient implementation of k stack in an array. In this post, same for queue is discussed. Following is the detailed problem statement.… Read More »

Connect n ropes with minimum cost

There are given n ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal… Read More »

An Interesting Method to Generate Binary Numbers from 1 to n

Given a number n, write a function that generates and prints all binary numbers with decimal values from 1 to n. Examples: Input: n =… Read More »

Priority Queue | Set 1 (Introduction)

Priority Queue is an extension of queue with following properties. Every item has a priority associated with it. An element with high priority is dequeued… Read More »

Queue – Linked List Implementation

In the previous post, we introduced Queue and discussed array implementation. In this post, linked list implementation is discussed. The following two main operations must… Read More »

Queue | Set 1 (Introduction and Array Implementation)

Like Stack, Queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out (FIFO).… Read More »

Find next right node of a given key

Given a Binary tree and a key in the binary tree, find the node right to the given key. If there is no node on… Read More »

Find the first non-repeating character from a stream of characters

Given a stream of characters, find the first non-repeating character from stream. You need to tell the first non-repeating character in O(1) time at any… Read More »

Iterative Method to find Height of Binary Tree

There are two conventions to define the height of a Binary Tree 1) Number of nodes on the longest path from the root to the… Read More »

Construct Complete Binary Tree from its Linked List Representation

Given Linked List Representation of Complete Binary Tree, construct the Binary tree. A complete binary tree can be represented in an array in the following… Read More »

Find the first circular tour that visits all petrol pumps

Suppose there is a circle. There are n petrol pumps on that circle. You are given two sets of data. The amount of petrol that… Read More »

Implement Stack using Queues

The problem is opposite of this post. We are given a Queue data structure that supports standard operations like enqueue() and dequeue(). We need to… Read More »

Find the largest multiple of 3 | Set 1 (Using Queue)

Given an array of non-negative integers. Find the largest multiple of 3 that can be formed from array elements. For example, if the input array… Read More »