# Category Archives: Combinatorial

## Number of ways to paint K cells in 3 x N grid such that no P continuous columns are left unpainted

Given three integers N, P and K, the task is to find the number of ways of painting K cells of 3 x N grid… Read More »

## Probability of getting all possible values on throwing N dices

Given an integer N denoting the number of dices, the task is to find the probability of every possible value that can be obtained by… Read More »

## Count of integers up to N which represent a Binary number

Given an integer N, the task is to count every number i from 1 to N (both inclusive) such that i is a binary representation… Read More »

## Sort decreasing permutation of N using triple swaps

Given an array A[] consisting of decreasing permutation of N numbers, the task is to sort the array using triple swaps. If it is not… Read More »

## Number of ways to choose K intersecting line segments on X-axis

Given an array arr[] of line segments on the x-axis and an integer K, the task is to calculate the number of ways to choose… Read More »

## Count of subsequences which consists exactly K prime numbers

Given an integer K and an array arr[], the task is to find the number of subsequences from the given array such that each subsequence… Read More »

## Number of strings which starts and ends with same character after rotations

Given a string str, the task is to find the number of strings that start and end with the same character after a rotation at… Read More »

## Count of K length subsequence whose product is even

Given an array arr[] and an integer K, the task is to find number of non empty subsequence of length K from the given array… Read More »

## Orbit counting theorem or Burnside’s Lemma

Burnside’s Lemma is also sometimes known as orbit counting theorem. It is one of the results of group theory. It is used to count distinct… Read More »

## Find the K-th Permutation Sequence of first N natural numbers

Given two integers N and K, find the Kth permutation sequence of numbers from 1 to N without using STL function. Note: Assume that the… Read More »

## Count of Binary strings of length N having atmost M consecutive 1s or 0s alternatively exactly K times

Given three integers, N, K and M. The task is to find out the number of binary strings of length N which always starts with… Read More »

## Sum of product of all subsets formed by only divisors of N

Given a number N, the task is to find the sum of the product of elements of all the possible subsets formed by only divisors… Read More »

## Product of all sorted subsets of size K using elements whose index divide K completely

Given an integer array arr[] of N distinct elements and a positive integer K ( K <= N ). The task is to calculate the… Read More »

## Number of ways to place two queens on a N*N chess-board

Given an integer N denoting a N * N chess-board, the task is to count the number of ways to place two queens on the… Read More »

## Maximum number of prime factors a number can have with exactly x factors

Given an integer X, denoting the number of factors of a positive integer N can have. the task is to find the maximum number of… Read More »