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 »
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 larger than this number. For example, if the input number is “2 3 5 4 5”, the… Read More »
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 »
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 »
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 »
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 »
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 »
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 »
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 »
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 »
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 »
Write a function Add() that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, ..… Read More »
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 »
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 »
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 »