Similar Trees

Write function to check whether two trees are similar or not. The signature of the function should be as shown below: /** * Function to […]

Find kth element in union of two arrays

Given two sorted arrays of size m and n respectively. Find the kth element in the merged result of A and B. For example, If the inputs (A, B […]

Splitting a linked list

Given a linked list, write code to split it into two lists each containing the  alternate (odd-even) nodes from the original. If the original list […]

Singleton design pattern

Singleton patterns are used, when you want to allow creation of only one instance(object) of a particular class. Such classes (which allow only single object […]

One Definition Rule (ODR) in C++

One Definition Rule (ODR) In C++, declaration does not allocate any memory. Its only when an object (or function) is defined that an instance of […]

C++11 feature – automatic type detection and decltype

C++11 is the latest version of C++ language originally designed by Stroustrup. I read an interview of him where he said that the latest standard […]

Allocating memory to n-dim Array on heap

Dynamic arrays are on heap. If an array is stored on heap, its address must be stored in pointer variables, else there will be no […]

Print ancestors of a node in a Binary Tree Node

Given a Binary tree and an integer, print all the ancestors of the node. For example: If the given tree is as below: Input: 5 […]

camel & banana puzzle

A Camel has to transport 3000 bananas from point A to point B, both 1000km apart. There are few constraints There is only one Camel. […]