Close

## Number of rectangles

Given a number of unit squares (1 x 1). How many different rectangles can be formed with them? For example let us consider 4 units. We can form 5 different rectangles like the following. Two rectangles are considered same if they are oriented in a different way but same dimensions. Basically we have to arrange…

## 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…

## Adding a list of big numbers

Most of the popular programming languages like C/C++, Java, C# provide primitive data types (int, long) to hold values up to only a specific range. A 64-bit integer can store only store numbers in the range of -264 to 263-1. This can store numbers containing roughly 19-20 digits.What if we have to deal with even…

## Number of trailing zeros in a factorial

This problem looks easy to solve for small numbers. Simply calculate the factorial and count how many zeroes are present at the end! But the factorial grows big very fast even for small numbers which cannot fit into standard data types. (20! = 2432902008176640000. Cannot fit into a long variable also). In summary this is…

## Permutation cycles – Code chef problem

This is a problem from CodeChef. Follow this link if you want to try this problem on your own. Given a permutation of numbers from 1 to N. You can walk through the permutation to find cycles in it.Here is how you can do it. Consider the permutation {3, 5, 2, 1, 4, 6} Start…

## Next Round – A problem from Codeforces

This problem is from Codeforces. If you want to solve this problem on your own, follow this link. Here is the simplified problem statement. Given a list of scores of contestants in a competition, arranged in decreasing order. We have to calculate the number of people qualified for the next round.This is determined as follows,…

## Inverse permutation problem

This problem is from code forces. If you want to try this problem, follow this link. Here is the simplified problem statement. Given a group of N friends, each one has given a gift to other friend or themselves. An input array is given which indicates from whom each one has received their gifts. We…

## A simple problem pattern in competitive programming

Consider the following two problems appeared in two different competitions, which underlies the same pattern. Given a number of chocolates (N). For each of M wrappers, we will get a chocolate free. How can one have the maximum number of chocolates by following an optimum strategy? Given a number of candles (N) each of them…