Skip to content

Category Archives: Mathematical

Given two integers k and n, write a function that prints all the sequences of length k composed of numbers 1,2..n. You need to print… Read More
Given a cost matrix cost[][] and a position (M, N) in cost[][], write a function that returns cost of minimum cost path to reach (M,… Read More
Given that integers are read from a data stream. Find the median of elements read so for in an efficient way. For simplicity assume, there… Read More
Given a positive number n, write a function isMultipleof5(int n) that returns true if n is multiple of 5, otherwise false. You are not allowed… Read More
Backtracking is an algorithmic paradigm that tries different solutions until finds a solution that “works”. Problems that are typically solved using the backtracking technique have… Read More
The Fibonacci numbers are the numbers in the following integer sequence.0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. In… Read More
Write a function to generate all possible n pairs of balanced parentheses.  Examples:  Input: n=1 Output: {} Explanation: This the only sequence of balanced parenthesis… Read More
Method 1 (Using Nested Loops): We can calculate power by using repeated addition. For example to calculate 5^6.  1) First 5 times add 5, we get… Read More
Given an array arr[] of n integers, construct a Product Array prod[] (of the same size) such that prod[i] is equal to the product of… Read More
You can win three kinds of basketball points, 1 point, 2 points, and 3 points. Given a total score of n, print out all the… Read More
Given an integer n, find whether it is a power of 4 or not. Example :  Input : 16 Output : 16 is a power… Read More
By making use of recursion, we can multiply two integers with the given constraints. To multiply x and y, recursively add x y times.   Approach: Since… Read More
Algorithm: This method can be derived from (but predates) Newton–Raphson method.   1 Start with an arbitrary positive start value x (the closer to the root, the… Read More
  There are 2 sorted arrays A and B of size n each. Write an algorithm to find the median of the array obtained after… Read More
Asked by Anshya. Base 14: Decimal numbers Base 14 numbers 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7… Read More