# Category Archives: Mathematical

## Make a fair coin from a biased coin

You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40%… Read More »

## Given a number, find the next smallest palindrome

Given a number, find the next smallest palindrome larger than this number. For example, if the input number is “2 3 5 4 5”, the… Read More »

## Generate integer from 1 to 7 with equal probability

Given a function foo() that returns integers from 1 to 5 with equal probability, write a function that returns integers from 1 to 7 with… Read More »

## DFA based division

Deterministic Finite Automaton (DFA) can be used to check whether a number “num” is divisible by “k” or not. If the number is not divisible,… Read More »

## Find day of the week for a given date

Write a function that calculates the day of the week for any particular date in the past or future. A typical application is to calculate… Read More »

## Sieve of Eratosthenes

Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. Example: Input… Read More »

## Magic Square

A magic square of order n is an arrangement of n2 numbers, usually distinct integers, in a square, such that the n numbers in all… Read More »

## Count numbers that don’t contain 3

Given a number n, write a function that returns count of numbers from 1 to n that don’t contain digit 3 in their decimal representation.… Read More »

## Check whether a given point lies inside a triangle or not

Given three corner points of a triangle, and one more point P. Write a function to check whether P lies within the triangle or not.… Read More »

## To find sum of two numbers without using any operator

Write a program to find sum of positive integers without using any operator. Only use of printf() is allowed. No other library function can be… Read More »

## Josephus problem | Set 1 (A O(n) Solution)

In computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement: There are n people standing… Read More »

## Add two numbers without using arithmetic operators

Write a function Add() that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, ..… Read More »

## Binomial Coefficient | DP-9

The following are the common definitions of Binomial Coefficients.  A binomial coefficient C(n, k) can be defined as the coefficient of x^k in the expansion… Read More »

## Coin Change | DP-7

Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1,… Read More »

## Minimum number of jumps to reach end

Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function… Read More »