Write function to check whether two trees are similar or not. The signature of the function should be as shown below: /** * Function to check whether two trees are similar or not. * @param r1, r2: Pointer to root nodes of two trees. * Returns true(1) if the two are similar, else false(0) */ […]
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 & K ) are as given below Then the merged result of the two arrays will be And the 6th (K’th) element = 8
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 is The It should split into two lists like below To make the final output look like (breaking the original list in two sublists)
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 to be created) are called Singleton Classes. For example, there is only one Window manager, so a class implementing Windows Manager, should be allowed to be instantiated only once.
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 it is created. The One definition Rule says that there cannot be more that one definition in a single translation unit of C++.
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 (C++11 or C++0x) feels like a new language. I will be publishing the new features added to the core language and to the STL in following articles in next few […]
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 way to access the array. Let us assume the Array to hold integers. Write a code to allocate memory to a 2-dim array and then generalize it to allocate memory […]
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. Camel can not carry more than 1000 bananas at one time. Camel eats one banana every kilometer when he travels. What is the maximum number of bananas which can be […]