Median in a stream of integers (running integers)

Given that integers are read from a data stream. Find median of elements read so for in efficient way. For simplicity assume there are no… Read More »

Print a given matrix in spiral form

Given a 2D array, print it in spiral form. See the following examples. Examples: Input: 1 2 3 4 5 6 7 8 9 10… Read More »

Check if a binary tree is subtree of another binary tree | Set 1

Given two binary trees, check if the first tree is subtree of the second one. A subtree of a tree T is a tree S… Read More »

Detect and Remove Loop in a Linked List

Write a function detectAndRemoveLoop() that checks whether a given Linked List contains loop and if loop is present then removes the loop and returns true.… Read More »

Print BST keys in the given range

Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Print all the keys of tree… Read More »

Sorted insert for circular linked list

Difficulty Level: Rookie Write a C function to insert a new value in a sorted Circular Linked List (CLL). For example, if the input CLL… Read More »

Print nodes at k distance from root

Given a root of a tree, and an integer k. Print all the nodes which are at k distance from root. For example, in the… Read More »

Sort an array of 0s, 1s and 2s

Given an array A[] consisting 0s, 1s and 2s. The task is to write a function that sorts the given array. The functions should put… Read More »

Reverse a Linked List in groups of given size | Set 1

Given a linked list, write a function to reverse every k nodes (where k is an input to the function). Example: Input: 1->2->3->4->5->6->7->8->NULL, K =… Read More »

Merge sort is often preferred for sorting a linked list. The slow random-access performance of a linked list makes some other algorithms (such as quicksort)… Read More »

Write a SortedMerge() function that takes two lists, each of which is sorted in increasing order, and merges the two together into one list which… Read More »

Intersection of two Sorted Linked Lists

Given two lists sorted in increasing order, create and return a new list representing the intersection of the two lists. The new list should be… Read More »

Maximum width of a binary tree

Given a binary tree, write a function to get the maximum width of the given tree. Width of a tree is maximum of widths of… Read More »

Run Length Encoding

Given an input string, write a function that returns the Run Length Encoded string for the input string. For example, if the input string is… Read More »

Reverse words in a given string

Example: Let the input string be “i like this program very much”. The function should change the string to “much very program this like i”… Read More »