Sorting a linked list of 0s, 1s and 2s
Given a Singly linked list with each node containing either 0, 1 or 2. Write code to sort the list. Input List: 1 -> 1 -> 2 -> 0 -> 2 -> 0 -> 1 -> 0 Output : 0 -> 0 -> 0 -> 1 -> 1 -> 1 -> 2 -> 2
Print first non-repeating character in the string
Given a String where characters are repeating. Write code to print the first character that is repeating later in the string. e.g, Input String: ritambhara Output: i Input String: social ritambhara Output: s
Adapter design pattern (wrapper)
We talked about the Facade design pattern yesterday which provides a wrapper over a sub-system (or a set of functionality. Adapter design pattern also provides a wrapper over the functionality of a class, the difference is that Adapter convert the interface of a class into another interface which clients expect. Adapter, the structural design pattern, […]
Number of possible triangles from given array of numbers
Given an array of numbers, write an algorithm to count how many triangles are possible with three numbers from array as their side. If input array is: {7, 3, 6, 4} Then the output should be 3 because there are 3 possible triangles, viz.: {3, 4, 6}, {3, 6, 7} and {4, 6, 7}.
Facade design pattern
Facade is a structural design pattern. It defines a higher-level interface that makes the subsystem easier to use. Facade means the mask (मुखौटा) and the pattern is nothing but a simplified interface to a more complex system by providing a wrapper for the sub-system. Consider starting your car, let us see what happens under the hood […]
Transpose of non-symmetric matrix
Given a M*N order matrix, which is stored in an array in a row-major order. eg. if the matrix is of order 2*4 with below elements a b c d e f g h Then it is stored in a one dimensional array as below: a b c d e f g h Write a program […]
Find non repeating number
Given an array of numbers where each number is repeating thrice. In that array one element is not repeating at all. Find that number. Input Array: {5, 9, 2, 5, 2, 5, 2} Output: 9
Multiton design pattern
Multiton is a Creational design pattern. It is just an extension of Singleton Pattern. Singleton allows creation of only one object of the class. The constructor is made private and objects are created only thru a static function which returns instance of the object. When this function is called first time, a new object of […]
Object pool design pattern
Have you gone to bowling ? You have to change your shoes before actually get to the bowling arena. There are lot of shoes in the shoe-shelf, you just need to pick the shoe that fits you, put it on and start playing. Once you are done, you return the shoes to the shelf, put […]
Prototype Design Pattern
Think of an Interior decorator. He will be performing the below two steps to suggest the decoration of interior to any client: For each client that comes to the designer, he will do the above two steps. The second step (designing the hall) is customized according to requirements of the client, but first step (creating […]