Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once. Expected time… Read More

# Category Archives: Mathematical

Given a number, check if it is divisible by 7. You are not allowed to use modulo operator, floating point arithmetic is also not allowed.… 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: … 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 in… 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