Close

## Number of characters appearing in all given strings

Given a set of n strings, we have to write a program to find out the number of characters appearing in all the strings.For example consider the following strings{“India”, “China”, “United states”}, the letters {a,i,n} appear in all the strings.Let us think of the following solution. We first add all the characters in the first…

## Finding the number of duplicates in a list of numbers

Given a list of numbers, we have to find how many duplicate entries are present in it? For example consider the list of numbers {5, 1, 9, 5, 2, 1, 6, 4, 5, 8}It has 3 duplicate numbers. There are many ways to do this. In this post, I present one of the simplest ways…

## Program to find the powerset of a given set

Given a set of numbers, how do we generate its power set? For example for the set {1,2} the power set is given below. {  {},  {1}, {2}, {1,2} } A power set is nothing but all the possible subsets of a given set. If a set contains N elements, it’s power set contains 2N…

## Longest Increasing Subsequence problem

Given an array of numbers, we have to find the longest sub sequence of that array which is strictly increasing.For example in the following array [8 1 4 2 7 9 5] {8,9}{1,4,7,9}{1,2,7,9}{1,2,5}{1,2,7}{1,2,9} are some of the increasing sub-sequences. The second and third are the longest increasing sub sequences with length 4. Our job is…

## Common elements between two sorted arrays

Given two sorted arrays, how do you efficiently find the common elements between those two?Method#1: Simple and Brute-force approachIterate through one array, and try to find the element in another array using linear search. If it is found, then print it. This approach takes O(n^2) time as for each element in the first array we…

## Finding duplicates from given set of numbers

Given a list of numbers. How do we write a program to find the duplicates among them?A simple algorithm is to compare each possible pair in the list to see if there are any duplicates. But this algorithm runs in O(n2) time. We can use the following simple algorithm using the set data structure. This…