Builder Design Pattern

Let’s understand it by understanding the assembling of computer. When you buy computer (in India), you have two choices, Buy the entire computer from a manufacturer (like HP or Dell), the way we buy laptops, or, Get it assembled. For this post, we are only interested in the second option. When you are assembling your […]

Abstract Factory Design Pattern

Abstract Factory is an extension to Factory Design Pattern discussed earlier. In fact the last method discussed in that post is nothing but an example of Abstract Factory design. If the product being produced in the factory requires to set up a separate factory (for a particular product) itself, then the case is fit for Abstract […]

Honest man playing card puzzle

An honest man holds a card which can be either ‘1‘, ‘2‘ or ‘3‘. You can ask one (and only one) question to the man. The man is allowed to answer only ‘Yes‘, ‘No‘ and ‘I don’t know‘. The honest man obviously never lies. What question will you ask so that you get to know about the […]

Chess board puzzle

Imagine you have infinite number of Queens. Find the minimum number of queens required so that every square grid on the chess board is under the attack of a queen. Arrange this minimum no. of Queens on a chess board.

Demo post 3

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum […]

Using sizeof to get size of an Array or pointer

sizeof operator returns size in bytes. For example, In an implementation where 2 bytes (16bits) of memory is allocated to an int type, the below code will output 2 int x = 10; printf(“%d”, sizeof(x)); // Output amount of memory allocated to int data type. We talked about the sizeof operator in great detail in the last post. If we […]

sizeof operator in C/Cpp language

sizeof is a unique operator in C/C++ language which returns the amount of memory (in bytes) allocated to its operand. For example, if an implementation stores an integer in 2 bytes then both the statements below will output 2. printf(“%d”, sizeof(int)); int x = 10; printf(“%d”, sizeof x); Note than sizeof operator is used like a […]

Factory Design Pattern

The Factory design pattern is an object-oriented Creational design pattern. It implements the code to allow creation of objects the way products are created in factories. The essence of this pattern is to “Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. Hence, deferring (postponing) the instantiation […]

Rotating a linked list around pivot

We have seen a question to rotate an array around a pivot earlier. Now write similar code for linked list. Given a linked list and an integer value ‘k’. Write a code to rotate linked list by k nodes from the end, as shown in the below diagram for k=2 Note that k nodes are counted […]