# Category Archives: Combinatorial

## Ways of filling matrix such that product of all rows and all columns are equal to unityNovember 22, 2017

We are given three values , and where is number of rows in matrix, is number of columns in the matrix and is the number… Read More »

## Number of subsequences as “ab” in a string repeated K timesNovember 14, 2017

Given a String S, consider a new string formed by repeating the S exactly K times. We need find the number of subsequences as “ab”… Read More »

## Dividing an array into two halves of same sumNovember 13, 2017

Given an even size array of integers. We need to find if it is possible to divide array elements into two sets such that following… Read More »

## Ways to paint stairs with two colors such that two adjacent are not yellowNovember 12, 2017

Given n stairs and we have 2 colour yellow and green the task is that we have to paint given stairs by given colour with… Read More »

## Smallest Derangement of SequenceNovember 6, 2017

Given the sequence find the lexicographically smallest (earliest in dictionary order) derangement of . A derangement of S is as any permutation of S such… Read More »

## Number of ways to get even sum by choosing three numbers from 1 to N

Given an integer N, find the number of ways we can choose 3 numbers from {1, 2, 3 …, N} such that their sum is… Read More »

## Count ways to express even number ‘n’ as sum of even integersNovember 5, 2017

Given an positive even integer ‘n’. Count total number of ways to express ‘n’ as sum of even positive integers. Output the answer in modulo… Read More »

## itertools.combinations() module in Python to print all possible combinations

Given an array of size n, generate and print all possible combinations of r elements in array. Examples: Input : arr[] = [1, 2, 3,… Read More »

## Count ways to express ‘n’ as sum of odd integers

Given an positive integer n. Count total number of ways to express ‘n’ as sum of odd positive integers. Input: 4 Output: 3 Explanation There… Read More »

## Distinct permutations of the string | Set 2November 4, 2017

Print all distinct permutation of a string having duplicates. Examples: Input : ABCA Output : AABC AACB ABAC ABCA ACBA ACAB BAAC BACA BCAA CABA… Read More »

## Generate permutations with only adjacent swaps allowed

Given a string on length N. You can swap only the adjacent elements and each element can be swapped atmost once. Find the no of… Read More »

## Count ways to form minimum product tripletsNovember 1, 2017

Given an array of positive integers. We need to find how many triples of indices (i, j, k) (i < j < k), such that… Read More »

## Lexicographically smallest permutation with distinct elements using minimum replacementsOctober 30, 2017

Given an array of n positive integers such that each element of integer is from 1 to n. Find the lexicographically permutation that can be… Read More »

## Counting sets of 1s and 0s in a binary matrixOctober 26, 2017

Given a n × m binary matrix, count the number of sets where a set can be formed one or more same values in a… Read More »

## Alexander Bogomolny’s UnOrdered Permutation AlgorithmOctober 19, 2017

The Alexander Bogomolyn’s algorithm is used to permute first N natural numbers. Given the value of N we have to output all the permutations of… Read More »