R@M3$H.NBlog
class Base { public: virtual void foo() {} }; class Derived: public Base { public: virtual void foo() {} }; int main() { Base *pBase…
print formatted JSON, XML from osx command line Working with various interfaces that output json or xml results in lots of situations where…
Problem: A River that cuts through a set of cities above and below it. Each city above the river is matched with a city below the river…
Redirect Part: When you click on a link of any tiny url, an HTTP Request is sent to their server with the full URL, like http // bit.ly / b…
I have a class A for example - A[] arr = new A[4]; But this is only creating pointers (references) to A and not 4 objects. Is this correct…
Interview Question: Is the following method thread-safe? How to make it thread-safe? This post explains a general interview question that…
Problem: Find inorder successor/predecessor of given node in binary search tree. In-order successor of a node is the node which will come…
WAP to modify the array such that arr[I] = arr[arr[I]]. Do this in place i.e. with out using additional memory. example : if a = {2,3,1,…
Why go? The Australian Grand Prix Corporation coined the phrase 'a great place for the race' and Melbourne is just that. Australia's second…
You’re in a car with a helium balloon on a string that is tied to the floor. The windows are closed. When you step on the gas pedal, what…
Spell the numbers out: Ten Nine Sixty Ninety Seventy Sixty-six They are in ascending order, based on the number of letters in the spelled…
A book has N pages, numbered the usual way, from 1 to N. The total number of digits in the page numbers is 1,095. How many pages does the…
He was playing Monopoly.
… and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The…
…You have access to a 100-story building. Eggs can be very hard or very fragile means it may break if dropped from the first floor or may…
…7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two…
…and your crew gets to vote on how the gold is divided up. If fewer than half of the pirates agree with you, you die. How do you recommend…
…, but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return…
Our (wrong) answer: Beef is always dead. Calling something "dead beef" is redundant -- a no-no for coders. The actual answer, from a reader…
22 times a day if you only count the minute and hour hands overlapping. The approximate times are listed below. (For the precise times, see…
Answer: Again, this one is all about the interviewer seeing how the interviewee would attack the problem. We'd start our answer by asking…
Answer: So it doesn't fall through the manhole (when the plane ordinarily flush with the plane of the street goes perpendicular to the…
Answer: We'd answer "However many the market dictates. If pianos need tuning once a week, and it takes an hour to tune a piano and a piano…
Read more: http://www.businessinsider.com/answers-to-15-google-interview-questions-that-will-make-you-feel-stupid-2009-11?op=1#ixzz2sHZEhAZr
Answer: This is one of those questions Google asks just to see if the applicant can explain the key challenge to solving the problem. Reader…
What method would you use to look up a word in a dictionary ? This is a classic binary search algorithm:
You are climbing a stair case. Each time you can either make 1 step or 2 steps. The staircase has n steps. In how many distinct ways can you…
The Indian Council of Agriculture Research (ICAR) in Ranchi has asked farmers to take up fruit production system (FPS) between big trees…
Cucurbit fruit fly is the most destructive pest of bitter gourd throughout the country. The pest attacks other cucurbitaceous vegetables…
It is a well accepted fact that feeding dairy animals is incomplete without including green fodder in their diet. However, the major…
An indigenous variety of brinjal popularised by a residential forum, ‘Niravu Vengeri,’ here has received a certificate of merit from the…
Call it an irony of sorts. Tomato farmers have been dumping their produce on the roads in some parts of northern Karnataka to express their…
You have to design a LRU cache such that all operations can be done in O(1) – read, write and insert. In case, cache is full, you have to…
What data structure to use for finding free parking spot in Parking Lot program? Assume there are million of parkings. Alternatively…
There are n nuts and corresponding bolts. However, all nuts and bolts are shuffled and we have to device a technique to pair them. No two…
Given a large file, how will you store the words in the file so that searching of a word can be done in constant time? Also how will you…
You Have File of Containing 1 Million Integers You need To Find 10 Maximum Integer Out of Them.How You Will Do That. What is Time & space…
How would you design an elevator algorithm ? Solution 1: http://en.wikipedia.org/wiki/Elevator_algorithm Solution 2: Elevator class: it has…
Designa a phone book - basically contact book on phone. Give data structures and give time complexity to search a phone number. Ex: search…
How to preprocess dictionary so that below operations are best supported a) Search in dictionary b) given a string find all valid…
Given a string, search it in a set of strings (say among 1000s of string). What data structure would you use to store those 1000 strings and…
Given a stream of numbers, suggest a data structure to store the numbers in the stream along with their number of occurrences. Solution…
The DNA double helix consists of a long strand of four bases: adenine (abbreviated A), cytosine (C), guanine (G) andthymine (T). Thus, it…
Given an array of strings (string[] inputStrings). Devise a way and write the code to determine and display all the anagrams in the array…
Given an input array of size unknown with all 1's in the beginning and 0's in the end. Find the index in the array from where 0's start…
External Sorting: Given a huge file with 2GB size with one string per line.Which algorithm to be used to sort the file and why? Concept: The…
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…
There are n bikes and each can cover 100 km when fully fueled. What is the maximum amount of distance you can go using n bikes? You may…
Over the past couple of years, auto-complete has popped up all over the web. Facebook, YouTube, Google, Bing, MSDN, LinkedIn and lots of…
A ternary search tree is a special trie data structure where the child nodes of a standard trie are ordered as a binary search tree…
How to call Base class method through base class pointer pointing to derived class You can do it through scope resolution operator…
Given an expression string exp, write a program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[","]” are correct in exp…
Implement a circular queue of integers of user-specified size using a simple array. Provide routines to initialize(), enqueue() and dequeue…
Problem: Design a dynamic stack which would perform following operations in O(1) time. 1.Push 2.Pop 3.Find middle 4.Delete middle Solution…
Question: There is a huge file containing billions of integers. Find maximum 20 integers form that file. Always remember that when you are…
At a bus-station, you have time-table for buses arrival and departure. You need to find the minimum number of platforms so that all the…
Introduction This article describes a fast and portable memcpy implementation that can replace the standard library version of memcpy when…
Spell checking with tries in C++: Part 1 Tries are a really cool data structure used for storing strings (and potentially other things…
I always thought that because of the reallocation vectors need to do as they grow in size, successively adding elements to one would be…
Copy a linked list with next and arbit pointer You are given a Double Link List with one pointer of each node pointing to the next node just…
Some solutions are: Making use of hash, but that would result in linear time complexity but very poor space complexity Sorting the list…
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate…
The above code throws the error: stl_function.h:237:22: error: no match for 'operator<' in '__x < __y' Method-1: (Overload the ) You need…
Introduction Dynamic programming have been a very interesting topic and technique to solve problems which exhibit a specific set of…
Socket Workflow To establish TCP connections the server host calls socket() to create a listening socket then specifies the IP address and…
From the C++ FQA Lite: [16.4] Why should I use new instead of trustworthy old malloc()? FAQ: new/delete call the constructor/destructor…
is legal and does what you would expect: it calls your class's destructor and free the underlying memory. After returns, your pointer…
The code posted here should be considered as pseudo-code, no particular language is assumed. And also it is assumed that the reader is…
Given an array of numbers, only one number appears once, others twice. Find the number. If there's only 1 number appearing once, it's…
A chemical equation is a theoretical or written representation of what happens during a chemical reaction. The law of conservation of mass…
Why is the size of an empty class not zero? To ensure that the addresses of two different objects will be different. For the same reason…
There are many uses of placement new. The simplest use is to place an object at a particular location in memory. This is done by supplying…
Can I overload the destructor for my class? No. Destructors never have parameters or return values. And you're not supposed to call…
A class declaration can contain static object of self type, it can also have pointer to self type, but it cannot have a non-static object of…
The C++ compilation process Compiling a source code file in C++ is a four-step process. For example, if you have a C++ source code file…
Definition: As you create objects statically (on the stack as opposed to allocating them in the heap memory) and perform function calls…
An array element X is one of leaders of the array if the all the elements following that array element is lesser than or equal to the array…
/* Returns true if the given tree is a BST and its values are >= min and <= max. / int isBSTUtil(struct node node, int min, int max) END
The diameter of a Binary tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree. The…
In current post we discuss how to find kth node from end of the linked list that contains loop. Finding kth node from the end of single…
In current post we discuss how to calculate length of the linked list when there is a loop in the linked list. Following procedure explains…
In this post we will discuss how to find the node that causes loop in linked list. Following procedure explains on how to detect node that…
The standard linear time solution for this is as follows: Take two pointers fast and slow Increment slow pointer by one node (node.next…
A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a…
by Richard Gillam Senior Software Engineer, Text & International Taligent, Inc. My team recently hired someone. Normally, this wouldn't be…
Problem: Reverse the words in a sentence. For example "Reversed Words" should become "Words Reversed". Comment: This is one of most…
Problem: Given a string of unknown length reverse it in place. Solution: Lets take a sample string "hello". When reversed it should read as…
Problem: Find if a given string is a palindrome. Palindrome is a word or a phrase that reads the same in either direction. Ex: A man, a plan…
Problem: Find the 1st non-repeated character in a string. Example: teetotaller The 1st non-repeated character is o. Solution: The solution…
Problem: You are given 2 strings. The first string is the input string that needs to be cleaned (in place) and the second string contains…
Problem: Implement atoi function in C language and give the test cases. atoi function converts a string to an integer. The function…
END
Problem: Write the code for producing/printing permutations of the characters in a string. For example: If "abc" is the input string, output…
Sort the array in-place and loop through to find the duplicate number Runtime: O(n log n) for sorting + O(n) Pros: no extra memory Cons…
Problem: You are given a sorted array with shifted elements. Elements can be shifted to the left or right by 'i' number of places. The sign…
Problem: You are given an array containing positive integers. All the integers occur even number of times except one. Find this special…
Problem: Write a function to perform a binary search on a Sorted Array. Solution: The recursive solution below runs in O(log(n)) because the…
Question: There are two sorted arrays A1 and A2. Array A1 is full where as array A2 is partially empty and number of empty slots are just…
To implement virtual functions, C++ uses a special form of late binding known as the virtual table. The virtual table is a lookup table of…
http://yourstory.in/2013/09/amrutha-dairy-farms-journey-it-to-dairy-farming-santhosh-d-singh/ Haalenahalli in Doddaballapur The original…
If the destructor in the base class is not made virtual, then an object that might have been declared of type base class and instance of…
string NumberToString(const int iVal) { string strNum ; stringstream ssOutput ; ssOutput << iVal ; strNum = ssOutput.str() ; return strNum…
The ubiquitous alternative to AF_INET (which, in retrospect, should have been named AF_INET4) is AF_INET6, for the IPv6 address family. IPv…
Emu Farming The Emu (Dromaius novaehollandiae), is the largest bird native to Australia It is also the second largest extant bird in the…
One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is…
string Num2String ( const int Num ) { stringstream ssOp ; ssOp<< Num ; return ssOp.str() ; }
GNU readline is a commonly used library for line-editing, it is used for example by bash, ftp and many more (see Arch Package details under…
The traditional solution is to allocate an array [footnote] of pointers to pointers, and then initialize each pointer to a dynamically…
First, K&R have an errata on this particular snippet: 117(§5.10): In the find example, the program increments . This is not specifically…
Introduction The Qt library provides a set of general purpose template-based container classes. These classes can be used to store items of…
The iterator appears to be constant, but doesn't return a constant iterator. Or, that's what I think because the mouseover error is…
For prefix searching, you can use to search for . This does not work for non-prefix substrings: in the general case, searching a map is…
For Sequence Containers: This will work for sequence containers like std::vector, but not for associative containers like std::map. The…
With GCC 4.1.2, to print the whole of a std::vector<int> called myVector, do the following: To print only the first N elements, do…
Lower bound: first element that is greater-or-equal. Upper bound: first element that is strictly greater. Example: As you can see, the half…
static_cast is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. performs…
Initializer List is used to initialize data members of a class. The list of members to be initialized is indicated with constructor as a…
Steps to get the backtrace from the core file with the corrupted stack. Run the gdb with the core file execute 'x /512xg $sp' Capture all…
When design interface, someone recommend to use non-virtual interface pattern. The essence of the non-virtual interface pattern is that you…
Design an LRU cache with all the operations including getting the least recently used item to be O(1)
When a C++ program starts, 5 distinct areas of memory are created. These are: Code Space: This is where the executable instructions of the…
#define SIZEOF(X) (unsigned int)( (char *)(&X+1)-(char *)(&X) ) struct sample *ptr; ptr=(struct sample*)0; printf("%d",++ptr); p…
The copy constructor is a special kind of constructor which creates a new object which is a copy of an existing one, and does it efficiently…
delete[] p The run-time system stores the number of objects, n, somewhere where it can be retrieved if you only know the pointer, p. There…
You can prevent an object being declared with automatic duration ("on the stack") by making its constructor private and providing a factory…
You could try to prevent an object being allocated dynamically ("on the heap") by making its private. To prevent accidental creation of an…
Interface: An interface only describes the actual signature of its methods etc. Any class implementing that interface must then provide an…
The difference here is that will place Hello world in the read-only parts of the memory and making s a pointer to that, making any writing…
When a Derived Class object is assigned to Base class, the base class' contents in the derived object are copied to the base class leaving…